开发者

How to access project files from NUnit tests

开发者 https://www.devze.com 2023-01-01 20:14 出处:网络
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

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 p开发者_StackOverflow社区rofile.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消