JetBrains, the company behind the excellent Resharper has this build/integration server called TeamCity. I thought that you had to pay to use TeamCity, but the professional version is actually free!

I recently hit a problem with CruiseControl.NET and its limited security so I decided to try TeamCity. The installation was smooth and setting up a project and getting it to build a project (via NAnt) was easy. The problem is however that TeamCity only supports NUnit and since I use xUnit I did not get any test results presented in the TeamCity web interface.

In order to solve this I began writing a custom NAnt task. There is no NAnt xUnit task in the xUnit release or in the codeplex source repository but there is a task for MSBuild and it was pretty easy to port this to an NAnt task. When I had the NAnt task working I added some special log messages. The way you integrate with TeamCity is through specifically formatted messages, for example:

##teamcity[testStarted name='HomeContollerTester ']

##teamcity[testFailed name='testname' message='failure message' details='stack trace']

TeamCity expects live reporting, test by test, as it uses the started/finished messages to time each test and to provide more dynamic reporting while the tests are running. This doesn't play well with the xUnit test runner as there is no callback before each test is executed only after. The TeamCity test report will list all tests as if they executed in less than 1ms:


To solve this problem I added the ability to export the test results to a html file (this feature was already present in the MSBuild task). You can publish this html report as an artifact in TeamCity.

<xunit assembly="XUnitTeamCityTest.dll"        
       workingDir="${out.dir}" />
<echo message="##teamcity[publishArtifacts '${results.dir}\test_report.html']" />

The NAnt echo task will just output the message to the build log which TeamCity will parse. The full test report with accurate timing information will then be available in the TeamCity web interface. Like this:


I really like how easy it is to integrate artifacts from the build script to the build server and make those publicly available. I will try to contact the xUnit team and see if I can contribute this. TeamCity support is the highest voted feature request for xUnit on codeplex :)

But until then here is the source: