How to Get Failed Tests to Fail a Build

- J.D. Meier, Jason Taylor, Alex Mackman, Prashant Bansode

When a build fails because of compilation errors, a work item is created to track the failure and the build is marked as failed. When an automated test fails, however, the build does not fail. The test failure is converted into a warning and the build continues.

You might want to fail the build if an associated automated test fails. You might also want to generate a work item automatically to track the failure.

To fail the build upon test failure
  1. Open the Microsoft.TeamFoundation.Build.targets file from Program Files\MSBuild\Microsoft\VisualStudio\v8.0\TeamBuild.
  2. Check out for edit and open the TFSBuild.proj file for the Team Build type you want to have failed upon test failure.
  3. Copy the RunTestWithConfiguration target from Microsoft.TeamFoundation.Build.targets to the end of the TFSBuild.proj file, just before the closing </Project> tag.
  4. Modify the ContinueOnError attribute from true to false.
Note: There will be two test tool tasks. Modify the end-to-end task in order to only modify the behavior of builds on the build server. Use the desktop build task when building on a developer’s desktop.

Alternatively, if you want all Team Build types to fail upon test failure, you can modify Microsoft.TeamFoundation.Build.targets directly. This change will modify behavior for all Team Build types.

The solution recommended above is straightforward to implement but is not guaranteed to continue working for future versions of Visual Studio. If you want to implement a solution that is guaranteed to continue working after upgrade, see Aaron Hallberg’s blog entry “Determining Whether Tests Passed in Team Build” at

Additional Resources

Last edited Jul 26, 2007 at 6:59 AM by prashantbansode, version 1


No comments yet.