Exclude Those Unit Tests!

Do you have a unit test that you don’t want to run in the nightly build? No problem.

Just add the TestCategory attribute to your test and give it a “DontRunWithBuild” name or something else memorable.


In Visual Studio, go to the Team Explorer, right-click on the build you want to exclude and click Edit Build Definition….

Edit Build Definition

Select the Process tab, expand Basic, Automated Tests, and Test Assembly. Enter “!DontRunWithBuild” (or whatever category name you chose) as the Category Filter.

TFS will run the tests that satisfy the filter condition. In this simple case, the “!DontRunWithBuild” means run tests that are NOT (!) in that category. You can also use other operators like AND (&) and OR (|). Details on how to set this up are found in the Create a Build Definition section of this page.


You can assign tests to multiple categories and tell the build to use multiple tests, so you could use this to mark certain tests as QA/DEV, Nightly/Weekly/Monthly etc.

Additional information is available here:

Related posts