Resharper Unit Test Runner Can't Find Content Files

做~自己de王妃 提交于 2019-12-01 03:07:20

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!