简体   繁体   English

如何配置Bamboo来构建NUnit测试?

[英]How to Configure Bamboo to Build NUnit Tests?

I am working on setting a project to use for CI testing, but have hit a hitch when attempting to compile unit tests. 我正在设置一个项目,以使用进行CI测试,但是在尝试编译单元测试时遇到了麻烦。 We are using the .NET framework 4.5 and NUnit v2.6.3.13283 . 我们正在使用.NET framework 4.5NUnit v2.6.3.13283 When I am in , I have set up the specific job to check out the source code when a new commit is pushed, and then use MSBuild to build the code. 当我在 ,我已经设置了具体的工作,以检查出的源代码当推一个新的提交,然后使用MSBuild来生成代码。 Unfortunately, when it reaches this second step, it decides that it no longer understands what NUnit is. 不幸的是,当到达第二步时,它决定不再了解NUnit是什么。

I have the nunit.framework.dll in the same directory (bin\\Debug) as the class .dll, so I'm definitely confused as to how I should go about having MSBuild work out building the NUnit tests. 我将nunit.framework.dll与类.dll放在同一目录(bin \\ Debug)中,因此对于应该如何让MSBuild解决构建NUnit测试的问题,我感到很困惑。

Any help would be appreciated. 任何帮助,将不胜感激。

EDIT: Error log for those not faint of heart. 编辑:错误日志为那些不晕倒的人。

c:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\Csc.exe /noconfig /nowarn:1701,1702 /nostdlib+ /platform:AnyCPU /errorreport:prompt /warn:4 /define:DEBUG;TRACE /reference:c:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\mscorlib.dll /reference:C:\\Windows\\Microsoft.Net\\assembly\\GAC_MSIL\\System.Core\\v4.0_4.0.0.0__b77a5c561934e089\\System.Core.dll /reference:"C:\\build-dir\\UCL-UNL-JOB1\\Unit Class Library\\bin\\Debug\\Unit Class Library.dll" /debug+ /debug:full /filealign:512 /optimize- /out:obj\\Debug\\UnitClassLibraryNUnitTests.dll /target:library AngleNUnitTests.cs "C:\\Users\\Bamboo\\AppData\\Local\\Temp.NETFramework,Version=v4.5.AssemblyAttributes.cs" c:\\ Windows \\ Microsoft.NET \\ Framework \\ v4.0.30319 \\ Csc.exe / noconfig / nowarn:1701,1702 / nostdlib + / platform:AnyCPU / errorreport:prompt / warn:4 / define:DEBUG; TRACE / reference:c :\\ Windows \\ Microsoft.NET \\ Framework \\ v4.0.30319 \\ mscorlib.dll /reference:C:\\Windows\\Microsoft.Net\\assembly\\GAC_MSIL\\System.Core\\v4.0_4.0.0.0__b77a5c561934e089\\System.Core.dll /参考:“ C:\\ build-dir \\ UCL-UNL-JOB1 \\ Unit类库\\ bin \\ Debug \\ Unit类Library.dll” / debug + / debug:full / filealign:512 / optimize- / out:obj \\ Debug \\ UnitClassLibraryNUnitTests.dll / target:library AngleNUnitTests.cs“ C:\\ Users \\ Bamboo \\ AppData \\ Local \\ Temp.NETFramework,Version = v4.5.AssemblyAttributes.cs”

AngleNUnitTests.cs(5,7): error CS0246: The type or namespace name 'NUnit' could not be found (are you missing a using directive or an assembly reference?) [C:\\build-dir\\UCL-UNL-JOB1\\UnitClassLibraryNUnitTests\\UnitClassLibraryNUnitTests.csproj] AngleNUnitTests.cs(5,7):错误CS0246:找不到类型或名称空间名称“ NUnit”(您是否缺少using指令或程序集引用?)[C:\\ build-dir \\ UCL-UNL-JOB1 \\ UnitClassLibraryNUnitTests \\ UnitClassLibraryNUnitTests.csproj]

AngleNUnitTests.cs(12,10): error CS0246: The type or namespace name 'Test' could not be found (are you missing a using directive or an assembly reference?) [C:\\build-dir\\UCL-UNL-JOB1\\UnitClassLibraryNUnitTests\\UnitClassLibraryNUnitTests.csproj] AngleNUnitTests.cs(12,10):错误CS0246:找不到类型或名称空间名称“ Test”(您是否缺少using指令或程序集引用?)[C:\\ build-dir \\ UCL-UNL-JOB1 \\ UnitClassLibraryNUnitTests \\ UnitClassLibraryNUnitTests.csproj]

etc. 等等

You need to use a previous task to MSBuild one (Maybe you could consider to use the VisualStudio Task it works like a charm). 您需要使用以前的任务来构建一个MSBuild(也许您可以考虑使用Visual Studio Task,它就像一个魅力一样)。

This previous task is a Command Task, it will update the Dlls related to the NuGet Package, in order to achieve it: 上一个任务是命令任务,它将更新与NuGet软件包相关的Dll,以实现此目的:

  1. Create a New Executable on Bamboo, pointing to the nuget.exe file (if you don't have it you could download from https://www.nuget.org/ 在Bamboo上创建一个新的可执行文件,指向nuget.exe文件(如果没有,则可以从https://www.nuget.org/下载)
  2. Create a New Command Task with the executable your created on the previous step. 使用在上一步中创建的可执行文件创建一个新命令任务。
  3. On the Argument field: "restore YourSolution.sln" 在参数字段上:“ restore YourSolution.sln”

In my approach I am using a VisualStudio task and after this one a MSTest Runner task. 在我的方法中,我使用的是VisualStudio任务,然后使用MSTest Runner任务。

I guess you are using NuGet? 我想您正在使用NuGet? If so, you need to enable NuGet Package restore, because MSBuild does not know how to resolve these NuGet packages. 如果是这样,则需要启用NuGet软件包还原,因为MSBuild不知道如何解析这些NuGet软件包。 This will create a .nuget directory in your solution which needs to be pushed the repository bamboo uses for the build. 这将在您的解决方案中创建一个.nuget目录,该目录需要推送到Bamboo用于构建的存储库。

Second problem I encountered when configuring the NUnit test runner with bamboo: the nunit-console.exe uses .NET Framework 3.5 which was not installed on my build server. 在用Bamboo配置NUnit测试运行器时遇到的第二个问题:nunit-console.exe使用的是.NET Framework 3.5,该版本未安装在我的构建服务器上。

When using Nuget with a source code repository, you have a couple of options. 将Nuget与源代码存储库一起使用时,有两种选择。

1) check in your nuget executable to source code and create a bamboo command task that calls that location relative to the build directory, ${bamboo.build.working.directory}\\tools\\Nuget.exe. 1)签入您的nuget可执行文件以获取源代码,并创建一个Bamboo命令任务,该任务调用相对于构建目录$ {bamboo.build.working.directory} \\ tools \\ Nuget.exe的位置。

2) Install the Nuget exe directly on the build server. 2)直接在构建服务器上安装Nuget exe。 Then you can create a new executable on Bamboo that you can reference in any task. 然后,您可以在Bamboo上创建一个新的可执行文件,可以在任何任务中引用。

To create a new executable for use in tasks, use this - https://confluence.atlassian.com/display/BAMBOO/Defining+a+new+executable+capability 要创建用于任务的新可执行文件,请使用以下命令-https://confluence.atlassian.com/display/BAMBOO/Defining+a+new+executable+capability

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

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