简体   繁体   English

ReSharper 单元测试未在 bin 目录中运行

[英]ReSharper Unit Test not run in bin directory

Preamble序言

I know, that this question seems to have anwsers here:我知道,这个问题似乎在这里有答案:

I have nearly the same problem like ReSharper 10 test runner failing to find AppSettings referenced from external file .遇到了几乎相同的问题,例如ReSharper 10 测试运行程序无法找到从外部文件引用的 AppSettings But these answer stated, that the problem should be gone with ReSharper 10.0.2但是这些答案指出,ReSharper 10.0.2 应该会解决这个问题

Question问题

I included a custom.xml files with custom settings, and I need to read them from my unit test.我包含了一个带有自定义设置的custom.xml文件,我需要从我的单元测试中读取它们。 But my file is not found.但是找不到我的文件。

I looked, where the process runs, and included this line我查看了流程运行的位置,并包含了这一行

var curdir = Directory.GetCurrentDirectory();

So I found out, that curdir is C:\\\\Users\\\\MYUSER\\\\AppData\\\\Local\\\\JetBrains\\\\Installations\\\\ReSharperPlatformVs11_000所以我发现, curdirC:\\\\Users\\\\MYUSER\\\\AppData\\\\Local\\\\JetBrains\\\\Installations\\\\ReSharperPlatformVs11_000

Now it is obvious that my file cannot be found.现在很明显我的文件找不到了。 After googling it, it found the above mentioned questions.谷歌搜索后,它发现了上面提到的问题。 But none of these solutions works for me.但是这些解决方案都不适合我。

These are my settings:这些是我的设置:

ReSharper 设置

Visual Studio Configuration Visual Studio 配置

Microsoft Visual Studio Ultimate 2012微软 Visual Studio Ultimate 2012

Version 11.0.61219.00 Update 5版本 11.0.61219.00 更新 5

Microsoft .NET Framework微软 .NET 框架

Version 4.6.01038版本 4.6.01038

Installierte Version: Ultimate安装版本:终极版

  • Architecture and Modeling Tools 04940-004-0038003-02857架构和建模工具 04940-004-0038003-02857
  • Team Explorer für Visual Studio 2012 04940-004-0038003-02857 Visual Studio 2012 团队资源管理器 04940-004-0038003-02857
  • Microsoft Team Explorer für Visual Studio 2012适用于 Visual Studio 2012 的 Microsoft 团队资源管理器
  • Visual Basic 2012 04940-004-0038003-02857 Visual Basic 2012 04940-004-0038003-02857
  • Microsoft Visual Basic 2012微软 Visual Basic 2012
  • Visual C# 2012 04940-004-0038003-02857 Visual C# 2012 04940-004-0038003-02857
  • Microsoft Visual C# 2012微软 Visual C# 2012
  • Visual C++ 2012 04940-004-0038003-02857 Visual C++ 2012 04940-004-0038003-02857
  • Microsoft Visual C++ 2012微软 Visual C++ 2012
  • Visual F# 2012 04940-004-0038003-02857视觉 F# 2012 04940-004-0038003-02857
  • Microsoft Visual F# 2012 Microsoft Visual F# 2012
  • Windows Phone SDK 8.0 - DEU 04940-004-0038003-02857 Windows Phone SDK 8.0 - DEU 04940-004-0038003-02857
  • Windows Phone SDK 8.0 - DEU Windows Phone SDK 8.0 - DEU
  • ASP.NET and Web Tools 2012.3.41009 ASP.NET 和 Web 工具 2012.3.41009
  • GenerateUnitTest 1.0生成单元测试 1.0
  • Git Source Control Provider 1.0.0.0 Git 源代码控制提供程序 1.0.0.0
  • JetBrains ReSharper Ultimate 10.0.2 Build 104.0.20151218.120627 JetBrains ReSharper Ultimate 10.0.2 内部版本 104.0.20151218.120627
  • Microsoft Advertising SDK for Windows Phone 6.2.923.0适用于 Windows Phone 6.2.923.0 的微软广告 SDK
  • Microsoft Advertising SDK for Windows Phone Build 6.2.923.0适用于 Windows Phone Build 6.2.923.0 的 Microsoft Advertising SDK
  • Microsoft XNA Game Studio 4.0微软 XNA 游戏工作室 4.0
  • Microsoft XNA Game Studio 4.0微软 XNA 游戏工作室 4.0
  • NuGet-Paket-Manager 2.8.60318.667 NuGet-Paket-Manager 2.8.60318.667
  • PreEmptive Analytics Visualizer 1.0 PreEmptive Analytics Visualizer 1.0
  • SQL Server Data Tools 11.1.20627.00 SQL Server 数据工具 11.1.20627.00
  • Microsoft SQL Server Data Tools Microsoft SQL Server 数据工具
  • Git Extensions Git 扩展

You don't list any version of NUnit installed, but you tagged this 'nunit' so I'm going to make an assumption you are using it!您没有列出安装的任何 NUnit 版本,但是您标记了这个“nunit”,所以我将假设您正在使用它! Further, I'm assuming NUnit >= 3.0... ignore this if otherwise.此外,我假设 NUnit >= 3.0 ... 否则请忽略这一点。 :-) :-)

NUnit 3.0 stopped changing current directory. NUnit 3.0 停止更改当前目录。 It's a bad idea for us to do that anyway and it's a really bad idea with 3.0, when multiple assemblies in differing directories may be running at the same time.无论如何,这样做对我们来说是一个坏主意,对于 3.0 来说,这是一个非常糟糕的主意,因为不同目录中的多个程序集可能同时运行。

So, assuming still it's an NUnit problem, instead of using a relative path, use TestContext.CurrentContext.TestDirectory as the location of your file.因此,假设它仍然是 NUnit 问题,而不是使用相对路径,而是使用 TestContext.CurrentContext.TestDirectory 作为文件的位置。

试试这个:

Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);

帮助我解决此类问题的事情 - 我刚刚在 ReSharper 设置中关闭了 NUnit 2.x 支持(ReSharper -> 选项... -> 工具 -> 单元测试 -> NUnit)。

设置

In my case was fixed when I changed to this setting在我的情况下,当我更改为此设置时已修复

我还关闭了 NUnit 2.x 支持,即使它显然与问题无关,它也解决了它(我有 ReSharper 2017.3.20180201.111630)

We are using TestCaseSource in our tests.我们在测试中使用 TestCaseSource。 So the fix for me in Rider version 2021.1.3 was to change Build-->Unit Testing-->NUnit to Test Runner因此,在 Rider 版本 2021.1.3 中对我的修复是将 Build-->Unit Testing-->NUnit 更改为 Test Runner 在此处输入图片说明

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

相关问题 resharper单元测试继承 - resharper unit test inheritance 从指定的文件夹重新共享运行单元测试,但是缺少应用程序配置文件 - Resharper run unit test from specified folder but missing application configuration file 在 Visual Studio/Resharper 中以调试模式运行单元测试时出现“不确定:测试未运行”错误 - “Inconclusive: Test not run” error running unit tests in debug mode in Visual Studio / Resharper Resharper-NUnit-无法运行单元测试,因为代码和测试项目二进制文件位于不同的位置 - Resharper - NUnit - unable to run unit tests because code and test project binaries in different locations 单元测试ReSharper和NUnit给出不同的结果 - Unit test ReSharper and NUnit give different results 单元测试实体框架将连接字符串设置为bin目录而不是App_Data - Unit Test Entity Framework sets connection string to bin directory instead of App_Data ReSharper 持续测试正在运行检测测试 - Detect test is being run by ReSharper Continuous Testing 如何从bin \\ debug目录在VS 2015中运行有序测试? - How is it possible to run Ordered test in VS 2015 from bin\debug directory? 使用Resharper调试VS 2013中的单元测试错误 - Error debugging unit test in VS 2013 using Resharper ReSharper单元测试运行器为外部类提供Inconclusive - ReSharper unit test runner gives Inconclusive to the outer class
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM