[TestMethod] 中的 Directory.CreateDirectory 行为异常
我对此一无所知......我创建了一些批处理代码,并进行了一些测试,在调用要测试的方法之前设置目录结构。问题可以通过
[TestMethod]
public void StupidTest()
{
Directory.CreateDirectory("./XXX");
Assert.IsTrue(Directory.Exists("./XXX"));
//new FileInfo( "./XXX/YYY.txt").Create().Close();
}
注释掉最后一行来说明,测试运行完美,但在测试结果的“Out”文件夹中,没有创建任何文件夹。当包含最后一行时,测试也会运行,并且 XXX 文件夹和 YYY.txt 文件都存在于用于测试运行的“Out”文件夹中。如果主体中仅包含测试的最后一行,则测试会失败,并抱怨路径不存在。
我发现一些参考文献提到了有关文件系统虚拟化的一些内容,并且测试应用程序没有足够的权限在“Out”文件夹中创建文件夹。
任何帮助将不胜感激!
I'm really in the dark on this one... I've created some batch processing code, and have several tests that setup a directory structure before calling the method to be tested. The problem can be illustrated by
[TestMethod]
public void StupidTest()
{
Directory.CreateDirectory("./XXX");
Assert.IsTrue(Directory.Exists("./XXX"));
//new FileInfo( "./XXX/YYY.txt").Create().Close();
}
When the last line is commented out, the tests runs perfectly, but in the "Out" folder of the testresults, no folder is created. When the last line is included, the test runs as well, and both the XXX folder and YYY.txt file exist in the "Out" folder for the test run. If only the last line of the test is included in the body, the test fails, complaining about a non-existant path.
I found some references mentioning something about file system virtualization, and the test app not having enough permissions to create folders in the "Out" folder.
Any help would be greatly appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试使用ProcessMonitor(来自MS下载站点,免费),并记录该进程的所有活动,然后我们可以查看该目录是否被创建、移动、删除等。
can you try and use ProcessMonitor (from MS download site,free), and record all of the activities of that process, and then we can see if the directory gets created, moved , deleted and so on.