当从命令行 运行 时,NUnit 看不到 configSource 定义的连接字符串

NUnit not seeing configSource defined connection strings when run from command line

我在使用 <connectionStrings configSource="connectionStrings.config"/>

将连接字符串从我的配置文件移动到 searate 文件后,在我的 Jenkins 构建服务器上进行 运行ning 自动化测试时遇到问题

当我从 Jenkins 工作区 在 VS2013 和 运行 测试中打开项目时,一切正常。当我尝试 运行 使用命令

将测试作为构建作业的一部分时
"C:\Program Files (x86)\NUnit 2.6.4\bin\nunit-console.exe" Path\To\Project\ProjectName.Tests.csproj /xml=TestResults.xml 

我在控制台中收到错误消息:

Test Error : ProjectName.Tests.TestClass.TestIfSomethingWorks
   System.InvalidOperationException : No connection string named 'ConnectionStringName' could be found in the application config file.

当然,app.config 文件和 connectionStrings.config 文件都位于测试项目和解决方案中使用这些连接字符串的项目的根文件夹中。

我做错了什么吗?如何解决这个问题?

我相信发生的事情是当您将它指向 csproj 文件时 nunit-console.exe 能够找到您的测试程序集,但它无法找到配置文件,因为它 运行 在不同的工作目录。您应该能够通过将 NUnit 指向您的测试程序集 DLL 来解决这个问题。像这样:

"C:\Program Files (x86)\NUnit 2.6.4\bin\nunit-console.exe" Path\To\Project\ProjectName.Tests\bin\Debug\ProjectName.Tests.dll /xml=TestResults.xml 

试一试,祝你好运!