Search

just show me the code

Thursday, January 29, 2009

Fail a Build when your Test Fails

Fail a Build when your Test Fails
ref: http://blogs.msdn.com/aaronhallberg/archive/2007/11/05/how-to-fail-a-build-when-tests-fail.aspx

Why
When a team build compiles with no errors, it is a success. If the test fail it gets marked as partially successful. Most would rather a failed test to mark the build as Failed.


Step1: Change your Target
The following code should be pasted into the bottom of your Team Build poject file and edited as necessary.

  252   <Target Name="AfterTest"> 
  253     <!-- Refresh the build properties. -->
  254     <GetBuildProperties TeamFoundationServerUrl="$(TeamFoundationServerUrl)"
  255       BuildUri="$(BuildUri)"
  256       Condition=" '$(IsDesktopBuild)' != 'true' ">
  257       <Output TaskParameter="TestSuccess" PropertyName="TestSuccess" />
  258     </GetBuildProperties>
  259
  260     <!-- Set CompilationStatus to Failed if TestSuccess is false. -->
  261     <SetBuildProperties TeamFoundationServerUrl="$(TeamFoundationServerUrl)"
  262       BuildUri="$(BuildUri)"
  263       CompilationStatus="Failed"
  264       Condition=" '$(IsDesktopBuild)' != 'true' and '$(TestSuccess)' != 'true' "  >
  265     </SetBuildProperties>
  266   </Target>

UPDATE
------------------------
http://drycode.blogspot.com/2009/04/tfs-fail-build-when-unit-test-fails.html


No comments:

Post a Comment

Contributors