简体   繁体   English

使用Resharper Nunit测试从随机临时目录开始

[英]Using Resharper Nunit tests start in a random temporary directory

I am using visual studio 2015 professional NUnit 3.2 resharper ultimate 10.0 我正在使用Visual Studio 2015 Professional NUnit 3.2 Resharper Ultimate 10.0

My goal is the read the correct app.config. 我的目标是读取正确的app.config。

This my code 这是我的代码

 [Test]
        public void MakeEngineLoad()
        {
            Debug.WriteLine(string.Format("Current directory: {0}", Directory.GetCurrentDirectory()));

            Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            Debug.WriteLine(config.FilePath);
            var engineConfig = (EngineConfigSection)ConfigurationManager.GetSection("engineConfig");
    }

This is the output 这是输出

Current directory: C:\\Users\怵303\\AppData\\Local\\JetBrains\\Installations\\ReSharperPlatformVs14 C:\\Users\怵303\\AppData\\Local\\Temp\\h1l4sot5.2xg\\da7be2d2-7401-4975-b37c-40fc13a14c8d.config 当前目录:C:\\ Users \\ u6035303 \\ AppData \\ Local \\ JetBrains \\ Installations \\ ReSharperPlatformVs14 C:\\ Users \\ u6035303 \\ AppData \\ Local \\ Temp \\ h1l4sot5.2xg \\ da7be2d2-7401-4975-b37c-40fc13a14c8d.config

I would like resharper to use the confile from the bin\\debug dir. 我希望重新共享器使用bin \\ debug目录中的配置文件。 I am even setting the option in resharper to start from the a specific dir. 我什至在resharper中设置选项以从特定目录开始。 Is this a bug with resharper or am i missing something? 这是Resharper的错误,还是我错过了一些东西?

Nunit 3 by default runs tests in a temporary directory. 默认情况下,Nunit 3在一个临时目录中运行测试。

To reach the directory the .exe was built in, you need to use TestContext.TestDirectory . 要访问.exe的内置目录,您需要使用TestContext.TestDirectory I'm unfamiliar with ConfigurationManager , but it looks like you can pass a path, so does the below work? 我不熟悉ConfigurationManager ,但是看起来您可以传递路径,那么下面的方法行得通吗?

ConfigurationManager.OpenExeConfiguration(TestContext.TestDirectory);

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM