Windows 10
Visual Studio 2017
TeamCity 2017.1.2
GitHub
我正在使用VS解决方案,该解决方案在本地表现如预期。主项目有一些程序包依赖性。测试项目对主项目有项目引用。 VS本地编译成功。主项目参考+相关性被复制到MyProject/bin/debug
;测试项目引用+依赖项被复制到MyProject.Tests/bin/debug
; ReSharper
本地运行测试成功。TeamCity:NUnit无法找到目标程序集的依赖关系
但是我的TC项目在运行测试时遇到问题。
我积累的配置步骤是:从GitHub拉,运行Visual Studio (sln) build
,触发NUnit.ConsoleRunner
运行测试VS内置组件 - 这将引发未找到错误(无法找到包的依赖组件)的文件,或许表明构建步骤需要保存为相关程序集的工件并将其复制到测试输出目录。
但是看在代理工作目录我发现同时出现在主项目和测试项目的依赖组件:
C:\TeamCity\buildAgent\work\64f706c42d79250c\{main-project}\bin\Debug\{dependency}.dll
和
C:\TeamCity\buildAgent\work\64f706c42d79250c\{tests-project}\bin\Debug\{dependency}.dll
这表明VS生成步骤按照预期将{dependency}.dll
复制到bin中。
那么为什么不能NUnit找到它?
[19:27:48][Step 5/5] MyProject.dll
[19:27:48][MyProject.dll] MyProject.UnitTests.MyTest
[19:27:49][MyProject.UnitTests.MyTest] System.IO.FileNotFoundException : Could not load file or assembly 'MyProjectDependency, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
[19:27:49]
[MyProject.UnitTests.MyTest] at ReferencingCode()
at MyProject.MyClass.Answer() in C:\TeamCity\buildAgent\work\64f706c42d79250c\MyProject\MyClass.cs:line 9
at MyProject.UnitTests.MyTest() in C:\TeamCity\buildAgent\work\64f706c42d79250c\MyProject\UnitTests.cs:line 10
[19:27:51][Step 5/5] Failed tests detected
我想知道如果输出迪尔斯都为VS Build
和NUnit
步骤不同?但是我的代理工作目录与我的本地VS解决方案目录相同 - 那么TC将在哪里找到NUnit
工作目录?
我不知道我明白你有什么问题以及你在做什么。单元测试不使用程序集。他们使用源代码。这是白盒测试。即单元测试直接与您的代码一起工作。 –
本地我的测试项目有一个项目引用到我的主项目; VS解决方案构建将主项目程序集及其依赖项程序集复制到测试项目的“debug/bin”文件夹中,然后“ReSharper”对这些程序集运行测试。 – BaltoStar