11
votes

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. 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?

3
Still having this problem in 2015! It's really a poor show from JetBrains. Their testing infrastructure is getting a bit fragile. I would think their test runner should be smart enough to copy content files to the test runner working directory.Tim Long

3 Answers

10
votes

Disabling the Unit Testing > Shadow-copy assemblies being tested Resharper option fixed this problem for me.

4
votes

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.

0
votes

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.