Subscribe Now: Feed Icon

Wednesday, June 8, 2011

TeamCity: Running Unit Tests

Summary: Running Unit Tests and Code Coverage using TeamCity

This is the third post in my TeamCity series, the first post is TeamCity: Easy Continuous Integration and the second is TeamCity: Building the Solution

After the last post which was too long this should be quite short. Remember in the last post I showed you the full list of build runners, then one of the build runners was MsTests (and another was NUnit).

So from the project view click on Edit Configuration Settings (in the upper right corner):

TeamCity-edit-project-settings

Now on the right click on 3 Build Step:

TeamCity-build-step

Now click on Add build step, in Runner type choose MsTest:

TeamCity-mstest-settings-1

Its optional but add a name to the step, in path to MSTest.exe either click on your version of VS (2010 = 10, 2005 = 9 …) or leave blank.

Testing with NUnit is pretty similar:

TeamCity-NUnit

The list of assemblies here and MsTest is of the dlls of the test projects from VCS root (from the setting of TFS Source Control). Just like in the previous post with the solution file.

TeamCity-Mstest-2 

On the bottom in .NET Coverage tool chose JetBrains dotCover, this uses TeamCity’s dotCover which gives pretty good results.

Click on Save. And that’s it.

 

TeamCity-mstest-result

Looking into the build run:

teamcity-msbuild-result-main-coverage

Looking at the full report:

teamcity-code-coverage-full-report

When reaching the class being tested:

teamcity-code-coverage-class

We can see that not all of the method is tested. In actuality I believe that code is inaccessible (can an enum value be empty so that it’s ToString will return an empty string?) but it’s good for the demonstration.

You can view the class here, and it’s tests here.