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?
-
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 Aug 15 '15 at 00:46
3 Answers
Disabling the Unit Testing > Shadow-copy assemblies being tested
Resharper option fixed this problem for me.

- 17,626
- 1
- 48
- 58
-
2We didn't want to make the resources embedded, so for us - this is a better solution/answer. +1 – Christoph Apr 25 '13 at 18:42
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.

- 6,863
- 2
- 40
- 33
-
This is possible the best and most robust way of handling tests with dependencies on external files. I've given up on Deployment items, even in VS2012 it seems that with ReSharper as the test runner DeploymentItems are still unpredictable. – nrjohnstone Sep 04 '13 at 09:02
-
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.

- 720
- 9
- 17