Thursday, December 18, 2014

Setting up Jetbrains TeamCity to run Visual Studio Unit Tests

If you are using Jetbrains TeamCity as your CI (Continuous Integration) server, there is a good chance that you also want to be able to run Unit Tests as part of your CI Build processes.

Well, fortunately, TeamCity includes a built-in MSTest Build runner to run your Unit Tests as well as bundles a version of Jetbrains dotCover in order to allow you to obtain Code Coverage results if you are not running a version of Visual Studio Premium edition or higher.

In order to set up TeamCity to run Unit Tests, you will need to do the following:

  1. Make sure that your previous build steps are using the Debug configuration.  If they are using the Release configuration, you will not have the necessary .pdb files in order to successfully run your Unit Tests and obtain your Code Coverage results.  
  2. Create a build step which uses the MSTest build runner
  3. Specify the version of MSTest that you are using on your build machine
  4. On each line of the "List assembly files" text area, specify the FULL PATH to each of the Unit Test assemblies.  Therefore, if the full path of the Unit Test assembly is something like %system.teamcity.build.workingDir%\MyUnitTests\bin\Debug\MyUnitTests.dll you will have to specify this full path. 
  5. For Code Coverage using Jetbrains dotCover, simply choose Jetbrains dotCover as the Code Coverage tool.
  6. Run your Build Step to ensure that it properly executes your Unit Tests and returns your Code Coverage results.
That is all there is to it!!


No comments:

Post a Comment