简体   繁体   English

Resharper单元测试运行器无法查找内容文件

[英]Resharper Unit Test Runner Can't Find Content Files

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. 我正在使用DeploymentItem属性来确保在VS之外运行mstest时将它们复制到输出目录。 However when using the Resharper test runner inside VS these files never make it to the directory that it is executing from. 但是,当在VS中使用Resharper测试运行器时,这些文件永远不会进入它正在执行的目录。 Anyone know how to fix this? 有人知道怎么修这个东西吗?

禁用Unit Testing > Shadow-copy assemblies being tested Resharper选项为我解决了这个问题。

我们通过将测试文件标记为嵌入资源来解决此问题,然后使用实用程序方法读取嵌入资源并将其写入预期位置。

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. 我也在努力进行基于NUnit的测试,我在测试项目中有文件,我希望在测试过程中将其读入。

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). 通过NCrunch运行工作正常,但使用Resharper,它无法找到该文件,因为它正在使用其他位置(例如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: NUnit中有一个内置属性:

TestContext.CurrentContext.TestDirectory

Now, everything is consistent across NCrunch, ReSharper and the built-in Visual Studio Test Explorer! 现在,NCrunch,ReSharper和内置的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. 希望在其他测试库中有一个等价物。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ReSharper单元测试运行器是否按顺序或与MbUnit并行运行测试? - Does the ReSharper unit test runner run tests sequentially or in parallel with MbUnit? 如何诊断Resharper Unit Test Runner“无法加载一个或多个请求的类型”错误 - How to diagnose Resharper Unit Test Runner “Unable to load one or more of the requested types” error ReSharper 10测试运行器未能找到从外部文件引用的AppSettings - ReSharper 10 test runner failing to find AppSettings referenced from external file 是否可以使用ReSharper作为测试跑步者? - Is it possible to use ReSharper as a test runner ONLY? 可以将ReSharper的测试运行器配置为不显示Debug.WriteLine()消息吗? - Can ReSharper's test runner be configure not to show Debug.WriteLine() messages? 单元测试ReSharper和NUnit给出不同的结果 - Unit test ReSharper and NUnit give different results 使用dotCover在执行单元测试期间访问作为“内容”构建的文件 - Access files built as “content” during unit test execution with dotCover 在ReSharper中是否有任何记录来查找为什么测试没有结果? - Is there any logging in ReSharper to find why the test is inconclusive? 绑定重定向不适用于ReSharper的NUnit测试运行器中的多个测试项目 - Binding redirect not working with multiple test projects in ReSharper's NUnit test runner 我们如何将ReSharper Test Runner 9.2定位到.Net 4.6,因此默认情况下它支持TLS 1.2? - How do we get the ReSharper Test Runner 9.2 to target .Net 4.6, so it supports TLS 1.2 by default?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM