[英]Resharper Unit Test Runner Can't Find Content Files
I have some tests that rely on some files I have marked as "Content" and to "Always Copy". 我有一些测试依赖于我标记为“内容”的一些文件和“始终复制”。 I'm using the DeploymentItem attribute to make sure they get copied to the output directory when running mstest outside of VS. 我正在使用DeploymentItem属性来确保在VS之外运行mstest时将它们复制到输出目录。 However when using the Resharper test runner inside VS these files never make it to the directory that it is executing from. 但是,当在VS中使用Resharper测试运行器时,这些文件永远不会进入它正在执行的目录。 Anyone know how to fix this? 有人知道怎么修这个东西吗?
禁用Unit Testing > Shadow-copy assemblies being tested
Resharper选项为我解决了这个问题。
我们通过将测试文件标记为嵌入资源来解决此问题,然后使用实用程序方法读取嵌入资源并将其写入预期位置。
I have also struggled with NUnit-based tests where I have files in the test project which I want to to be read in as part of the test. 我也在努力进行基于NUnit的测试,我在测试项目中有文件,我希望在测试过程中将其读入。
Running via NCrunch works fine, but with Resharper, it cannot find the file as it's using another location (such as C:\\Users\\myuser\\AppData\\Local\\JetBrains\\Installations\\ReSharperPlatformVs15_f6172a1d_000). 通过NCrunch运行工作正常,但使用Resharper,它无法找到该文件,因为它正在使用其他位置(例如C:\\ Users \\ myuser \\ AppData \\ Local \\ JetBrains \\ Installations \\ ReSharperPlatformVs15_f6172a1d_000)。
After tearing my hair out, I finally found the solution. 撕掉我的头发后,我终于找到了解决方案。 Instead of using 而不是使用
Environment.CurrentDirectory
or 要么
System.Reflection.Assembly.GetEntryAssembly().Location
There is a built-in property in NUnit: NUnit中有一个内置属性:
TestContext.CurrentContext.TestDirectory
Now, everything is consistent across NCrunch, ReSharper and the built-in Visual Studio Test Explorer! 现在,NCrunch,ReSharper和内置的Visual Studio Test Explorer的一切都是一致的! (Reminder: you do still have to set "Build Action" = "Content" and Copy to Output Directory" = "Copy Always") (提醒:您仍然需要设置“构建操作”=“内容”并复制到输出目录“=”始终复制“)
Hopefully there is an equivalent in other test libraries. 希望在其他测试库中有一个等价物。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.