I have some Tests that I run with ReSharpers "Run All Tests from Solution" feature. One of the classes being tested has a dependency on a file in the same folder as the assembly containing it. This file is copied to the output directory via MSBuild (set "Copy To Output Directory" to "Copy always").
Problem: The tests are not being run from the normal assembly output directory, but instead some temporary location in my user profile.
Therefore, I don't really know where to look for the file - the test runner does not copy it there. Can I force it to?
NUnit website recommends in this exact case to use Assembly.CodeBase property, that leads to the bin/debug I needed.
"Note: If you are tempted to disable shadow copy in order to access files in the same directory as your assembly, you should be aware that there are alternatives. Consider using the Assembly.Codebase property rather than Assembly.Location."
The .Location returned Uri style address "file:////D://Projects ... ", so the actual code I used was
string applicationDirectory = new Uri(Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase)).LocalPath;
Sounds like you're running your tests with the Shadow Copy option turned on.
Go to Resharper->Options and select the Unit Testing tab (right at the bottom of the list). Uncheck "Shadow-copy assemblies being tested" and try again.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With