Resharper 单元测试运行程序找不到内容文件

发布于 2024-09-30 22:05:59 字数 153 浏览 1 评论 0原文

我有一些测试依赖于我标记为“内容”和“始终复制”的一些文件。我使用 DeploymentItem 属性来确保在 VS 外部运行 mstest 时将它们复制到输出目录。然而,当在 VS 中使用 Resharper 测试运行器时,这些文件永远不会进入它正在执行的目录。有人知道如何解决这个问题吗?

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. However when using the Resharper test runner inside VS these files never make it to the directory that it is executing from. Anyone know how to fix this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

心房敞 2024-10-07 22:05:59

禁用单元测试>正在测试的卷影复制程序集 Resharper 选项为我解决了这个问题。

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

太阳男子 2024-10-07 22:05:59

我们通过将测试文件标记为嵌入式资源来解决这个问题,然后使用

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.

Saygoodbye 2024-10-07 22:05:59

我还在基于 NUnit 的测试中遇到了困难,其中我在测试项目中有文件,我希望将其作为测试的一部分读取。

通过 NCrunch 运行效果很好,但使用 Resharper 时,它无法找到该文件,因为它正在使用另一个位置(例如 C:\Users\myuser\AppData\Local\JetBrains\Installations\ReSharperPlatformVs15_f6172a1d_000)。

撕扯头发后,我终于找到了解决办法。而不是使用

Environment.CurrentDirectory

or

System.Reflection.Assembly.GetEntryAssembly().Location

NUnit 中有一个内置属性:

TestContext.CurrentContext.TestDirectory

现在,NCrunch、ReSharper 和内置 Visual Studio Test Explorer 中的所有内容都是一致的! (提醒:您仍然需要设置“Build Action”=“Content”并“Copy to Output Directory”=“Copy Always”)

希望其他测试库中也有类似的设置。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文