[英]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
所以我发现,
curdir
是C:\\\\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:这些是我的设置:
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安装版本:终极版
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)。
我还关闭了 NUnit 2.x 支持,即使它显然与问题无关,它也解决了它(我有 ReSharper 2017.3.20180201.111630)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.