Running unit tests on Team Foundation Server (TFS) builds

Dan Esparza picture Dan Esparza · Nov 13, 2008 · Viewed 26.4k times · Source

What are the steps to get Team Foundation Server running unit tests when a given build runs?

What are the caveats / pitfalls / workarounds a dev or sysadmin should be aware of when setting up a TFS server to do this for the first time?

What are common troubleshooting steps for unit test problems during builds?

Answer

Mr. Kraus picture Mr. Kraus · Nov 14, 2008

it depends on which version of TFS you are running, so I will assume it is 2008.

Firstly, you must have Team Edition for Testers installed on the computer that will act as your build agent, as stated in How To: Create a Build Definition

There are a couple of ways to tell Team Build to run tests for your build.

  1. Unit tests can be run from a defined Test List within the Solution being built. This list is referenced by the build definition and all tests within the chosen list(s) are executed. More info here
  2. WildCard test exectution is also available by defining a wildcard mask (i.e. Test*.dll) that instructs Team Build to run any tests present in assemblies that match the mask. This is done when defining the build definition as well.

Things to note:

If you intend to use the wildcard method and want to enable code coverage for your test configuration, you must add the following to your build definition file to enable it.

<RunConfigFile>$(SolutionRoot)\TestRunConfig.testrunconfig</RunConfigFile>

See my previous question on this for more info here