Invitation Digital Tech Blog

Building Scalable & Responsive Architecture

By

Running xUnit.net 2.0 tests in TeamCity

The final 2.0 release of xUnit came out recently (NuGet). We use this testing framework for our automated tests as these tend to be longer-running than unit tests, and xUnit supports parallel execution. Although they have a nice GitHub-hosted site now, documentation for xUnit tends to be a little hard to find and a bit scattered over the web. So here are some simple instructions to get xUnit working both within Visual Studio and as part of a TeamCity build.

First, update (or install) the xUnit package across your solution: update-package xunit in the Package Manager Console.

Update or install the xUnit Visual Studio runner, allowing you to easily run the tests inside Visual Studio: update-package xunit.runner.visualstudio. If you use ReSharper, there’s an xUnit extension to make ReSharper’s test runner xUnit-aware.

Download the xUnit2Runner TeamCity plugin, and copy the “xunit2Runner” folder and the “xunit2Runner.zip” file to the “plugins” folder in your build server’s TeamCity “data directory” (ours was TeamCity.BuildServer). If you have TeamCity 9.0 or above, the plugin will be copied to all your build agents. Prior to 9.0, you need to restart the TeamCity Server service.

Create a new Build Step in a TeamCity Build Configuration, choosing the “xUnit2” runner type:

xUnit2 Build Step in TeamCity

If you get an error in the Build Log like Unknown test framework: Could not find xunit.dll or xunit.execution.desktop.dll., it’s likely that your tests aren’t using the same version of xUnit as the TeamCity plugin.