-
Notifications
You must be signed in to change notification settings - Fork 30
Getting started with the nUnit activity
NOTE: In VS/TFS 2012 unit testing is based on an extensible system, it is no longer limited to only supporting MSTest as in previous versions of Visual Studio. If the nUnit adapter is downloaded from Visual Studio Gallery then nUnit tests can be included within a solution and build without the need for this custom activity.
Using the new test adapters should be the preferred option instead of this activity.
See the ALM Rangers Build Customization Guide for details in using the new test framework adaptors
The nUnit activity can be used to run nUnit based unit test and publish their results to TFS such they appears in the same reports as MStest based unit tests. In this example we aim to show the the basic steps that are required to get the activity integrated into a build.
Before you can make use of any of the TFS community build activities you have to make sure they are available for the build system and on your development PC. Instructions for this process can be found in the ALM Rangers build guide or in the getting started page of this wiki. This page assumes the nUnit is available in the developers build process workflow toolbox. Hence we are able to build the workflow shown below
The first step is find the MSTest section in your build process, it reasonable to put the nUnit tests at the end of the existing “Try Run Tests” section. This simple integration simply runs the nUnit tests, it make no attempt to modify any flow based on the test results. In the chosen location add a FindMachingFiles activity (from the Team Foundation Build Activities tab in the toolbox). In the workflow above it has the display DisplayName of “Find files containing nUnit tests”. As the name suggests this activity is used to find all the assemblies that could potentially contain tests by scanning the BinariesDirectory and below for assemblies ending in *.Tests.dll.
The result of this find is stored in a workflow variable FilesContainingTests. This should to be created with a type of IEnumerable; it’s scope, in the default workflow, was set to Compile and Test. Once the variable was created the activities output can be assigned to it
The nUnit activity runs the nUnit console EXE, produces the results as an XML file which is transformed to the Microsoft TRX format and published to TFS. To manage this the nUnit activity has many properties, but tests can be run with very few set if required. Ones that can be critical Version or ToolPath. If the ToolPath (the directory containing the nUnit console application) is not set the path to the nUnit console is built from the Version. This can be a problem if the program is not installed in the expected default location; hence if can be easier to just specify the whole ToolPath.
You also need to provide a name for the OutputFile and OutputXMLFile so the results can be stored, and to be able to publish the test results to TFS you must specific the Flavour and Platform as well as the PublishTestResults flag.
One gotta is that, if you have not specifically set these in the build definition (as in graphic below)
and you attempt to use the PlatformConfiguration object to provide the Flavor and Platform (as opposed to hard coded strings) empty strings will be passed into the nUnit activity and the publish will fail with the error
Running C:\Program Files (x86)\NUnit 2.5.10\bin\net-2.0\nunit-console.exe /nologo "C:\Builds\1\MSFAgile\BuildCustomisation\Binaries\ClassLibrary1.Tests.dll" /xml="\typhoon\drops\BuildCustomisation\BuildCustomisation_20110818.16\outputxmlfile.xml" /out="outputfile.txt" Processing \typhoon\drops\BuildCustomisation\BuildCustomisation_20110818.16\outputxmlfile.xml When publishing test results, both Platform and Flavor must be specified
So the minimum properties for the nUnit activity are as shown below
When the build runs you should see in the log that nUnit has been run with the correct command line options
and from the build summary page you can follow the link to see the test details
This is a very basic integration of the nUnit activity into a build. For more details on the other available properties check the nUnit console command line reference