Resharper Unit Test Runner Can't Find Content Files

前端 未结 3 704
有刺的猬
有刺的猬 2021-01-11 15:49

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 ou

相关标签:
3条回答
  • 2021-01-11 16:19

    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 讨论(0)
  • 2021-01-11 16:25

    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.

    0 讨论(0)
  • 2021-01-11 16:26

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

    0 讨论(0)
提交回复
热议问题