Since we use private GitHub repositories for our code, we needed something to easily manage our builds. When we had a new project recently start up, we decided it was time to take the plunge with TeamCity. However, we found a problem with this: we use fakes for unit testing, something that requires the Visual Studio 2012 test runner (vstest.console.exe) to execute the tests.

Having the builds report unit test results and code coverage was important so we dug into TeamCity and did some Google searches to see if we could get what we needed.

Prerequisites

Not much is needed to get started. Visual Studio 2012 must be installed on the TeamCity build agent so we can manually execute the vstest.console.exe. But otherwise it’s pretty straightforward.

Note: This was built and tested using Team City version 7.1.4 (build 24331).

vstest.teamcity.logger

The first key to getting this working was being able to run the vstest.console.exe from the command line and have the results reported back to TeamCity so the build can be logged. We found a custom Visual Studio logger on GitHub that did the job. We just downloaded the project, built the DLL, and placed it in the directory specified in the README file.

Executing tests with Windows PowerShell

Next, we created a PowerShell script (that we made available on GitHub) to be used in a TeamCity build step and search your solution directories for test assemblies that match “*Tests.dll”. It will separate the assemblies that use fakes since these will not correctly run using dotCover for code coverage. The script has four parameters that need to be passed to it:

  • rootDirectory – The solution directory
  • configName – Used to create a folder for coverage files
  • filters – a list of dotCover filters for including/excluding assemblies
  • vsConfigName – The name of the Visual Studio Configuration you are building (This is the folder it will search for Test Assemblies)

The script will run dotCover on all the test assemblies not using fakes and provide the import the data back into TeamCity.

Sample Build Step

Sample build step

After that we can set up our new PowerShell step to run our unit tests.

We can set up our new PowerShell step to run our unit tests.

Results

Results

Conclusion

We hope integration between TeamCity and the Visual Studio 2012 test runner is coming, but in the meantime I think what we’ve come up with will serve us well.

Looking For Helpful Content?

Sign up to receive useful software development tips and news from the Don't Panic Labs team.

You have successfully subscribed!

Share This