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 attrib开发者_运维技巧ute to make sure they get copied to the output directory when running mstest outside of VS. However when using the Resharper test runner inside VS these files never make it to the directory that it is executing from. Anyone know how to fix this?
Disabling the Unit Testing > Shadow-copy assemblies being tested
Resharper option fixed this problem for me.
We solved this problem by marking the test files as embedded resources and then used a utility method to read the embedded resource and write it to the expected location.
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.
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).
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:
TestContext.CurrentContext.TestDirectory
Now, everything is consistent across NCrunch, ReSharper and the built-in 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.
精彩评论