简体   繁体   中英

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. We are using the .NET framework 4.5 and NUnit 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. Unfortunately, when it reaches this second step, it decides that it no longer understands what NUnit is.

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.

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"

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(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]

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).

This previous task is a Command Task, it will update the Dlls related to the NuGet Package, in order to achieve it:

  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/
  2. Create a New Command Task with the executable your created on the previous step.
  3. On the Argument field: "restore YourSolution.sln"

In my approach I am using a VisualStudio task and after this one a MSTest Runner task.

I guess you are using NuGet? If so, you need to enable NuGet Package restore, because MSBuild does not know how to resolve these NuGet packages. This will create a .nuget directory in your solution which needs to be pushed the repository bamboo uses for the build.

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.

When using Nuget with a source code repository, you have a couple of options.

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.

2) Install the Nuget exe directly on the build server. Then you can create a new executable on Bamboo that you can reference in any task.

To create a new executable for use in tasks, use this - https://confluence.atlassian.com/display/BAMBOO/Defining+a+new+executable+capability

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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