How do you run nunit tests in Bamboo?
Asked by Paul Rempel:

I have a .NET Solution that is built in Bamboo (3.03) using the MSBUILD builder. That builds several assemblies including some nunit test assemblies. I want to run nunit and generate test results after the solution file is built successfully.

How do you do this? Ie. What builder should I use? Do I need multiple Jobs for the Plan? And does the procedure change if I upgrade to a newer version of Bamboo?

I've tried creating a second Job which will run nunit-console.exe after the first Default Job has built the assemblies. The problem is that when the second job runs, it is in its own subfolder with a new copy of the repository files, which does not include the freshly compiled dll's from the previous Job.


Answers:
author: Joe Clark
body: **EDIT:**I thought there was built-in support for running NUnit tests in Bamboo 3.1, but I was stupidly mistaken. There is a built-in test result parser, but shelling out to a batch script or a custom MSBuild task is still the "best" way to go for now.

-------------------------

If you're able to upgrade to Bamboo 3.1, there is built-in support for running NUnit Tests and parsing NUnit XML Result files as stand-alone tasks in a build. Check out the [release notes](http://confluence.atlassian.com/display/BAMBOO/Bamboo+3.1+Release+Notes#Bamboo3.1ReleaseNotes-.NetSupport).

Otherwise, I think the easiest solution is to edit your MSBuild file and use the [MSBuild Community Tasks](http://msbuildtasks.tigris.org/) to call NUnit to execute your tests. For example, a skeleton implementation of this in MSBuild would look something like this:

\<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"\>

\<Import Project="lib\\MSBuild.Community.Tasks.Targets" /\>

\<Target Name="Test"\>

\<NUnit Assemblies="bin\\Debug\\MyAssemblyToTest.dll" ToolPath="C:\\Program Files\\NUnit 2.5.10\\bin\\net-2.0" OutputXmlFile="bin\\Debug\\TestResults.xml" /\>

\</Target\>

\</Project\>

comments: author: Paul Rempel
body: I'll try upgrading to 3.1. From the release notes it looked to me like it was just an NUnit Parser to parse results, not necessarily to run it. I'd be happy to upgrade if it lets me run the tests!

I'm trying to avoid changing the build file so that they don't run on every developer build automatically (I know I can use conditional testing to only run in on Release builds), but I'll do it that way if I have to. Thanks.


author: Joe Clark
body: Darn, you're right. I thought there was a new task just for running NUnit tests, but I must have imagined it!  

You could configure a stand-alone task to run a custom MSBuild file that is not part of the main solution, so it won't run as part of every developer's build. Something like this: <http://screencast.com/t/vT9MIUXI7tAL>

<br />

I know I'm probably sounding like a sales pitch, but the tasks configuration in 3.1 is really flexible and I think it's awesome! :-)


author: James Dumay
body: There is an [issue open to introduce an nunit runner](https://jira.atlassian.com/browse/BAM-8702) to the Bamboo .NET Plugin. Please vote, comment and harass us about it on the issue!

The [.NET plugin is open source](https://bitbucket.org/atlassian/bamboo-dotnet-plugin) too - so if your feeling adventureous you could hack a runner together pretty easily :)


Tags: .net