čtvrtek 19. května 2016

Atlassian Bamboo and xUnit testing

I needed to run xUnit test on the Atlassian Bamboo Cloud (OnDemand) build server. It has no runner for xUnit, but can be run from the command line by xunit.runner.console.

Configure your build server


On the build server, just NuGet the runner:
nuget.exe xunit.runner.console
The Bamboo cannot parse xUnit output. It can handle the nUnit output nd the xUnit has an option to print results in the nUnit format. So, create a simple xunit.cmd script:
@echo off
@rem xunit runner for Bamboo

if "%2"=="" (
  echo Usage: test.dll report.xml
  exit /b 1
)

if not exist %~dp2 mkdir %~dp2

"c:\path\to\xunit.runner.console.2.1.0\tools\xunit.console.exe" %1 -nunit %2

Configure Bamboo


Then go to your Bamboo Administration - Agents Summary and choose your agent. Add a new capability:
Capability typeExecutable
Executable labelxUnit
Pathc:\path\to\xunit.cmd

To add the xUnit to you plan's job, just add the Command task after the project build (e.g. MSBuild, or NAnt). I expect you have a module MyProjectTests in your solution. Then configure the xUnit task:
ExecutablexUnit
Argumentbin\Release\MyProjectTests.dll test-reports\MyProjectTests.xml
Working sub directoryMyProjectTests

The final trick is to add the NUnit Parser task, just take care to put is as the final task:
NUnit Test Results File/DirectoryMyProjectTests/test-reports/*.xml

The bamboo logic is, that:
  1. Any task fails, and no test result is found, it assumes the compilation error has occurred.
  2. Any task fails, and a test result is found, it assumes a test has failed.
  3. All tasks pass, the build is OK. If the test results are found, they are picked up.

Žádné komentáře: