DirectoryInfo.Exists 在 MSTest 期间始终返回 false
我的应用程序的边界有一些处理创建目录的逻辑。我想测试它是否确实按预期创建目录,但是 DirectoryInfo.Exists 属性始终返回 false,即使目录实际存在。
另请参阅此问题 - 您需要设置一个断点才能查看该目录实际上已创建,因为 MSTest 会在测试结束时删除它。
是否有一些设置告诉 MSTest 在测试期间允许“正常”文件系统 IO?
I have a little bit of logic at the boundary of my app dealing with creating directories. I would like to test that it actually creates directories as expected, but the DirectoryInfo.Exists property always returns false even when the directory actually exists.
See also this question - you need to set a breakpoint to see that the directory has actually been created because MSTest will delete it when the test ends.
Is there some setting that tells MSTest to allow "normal" filesystem IO during tests?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设您稍早创建了 DirectoryInfo 实例,其中涉及一些目录状态的内部缓存 - 如果您调用 DirectoryInfo.Refresh() 来强制更新,这应该可以工作:
Assuming you create the DirectoryInfo instance somewhat earlier there is some internal caching of directory state involved - if you call
DirectoryInfo.Refresh()
to force an update this should work: