locked
Fail build when unit tests fail RRS feed

  • Question

  • We have created a custom build script that performs a ClickOnce deployment at the end of it. We've tried to create the deploy target in such a way that it only runs conditionally, but our condition doesn't seem to be working correctly, and I can't seem to figure out why. I'm hoping someone here can help shed some light on why.

    We've overridden the AfterEndToEndIteration target in the following way:

    <Target Name="AfterEndToEndIteration" Condition="'$(IsDesktopBuild)'!='true'">  
        <Message Text="TestStatus = $(TestStatus)" /> 
        <MSBuild Projects="$(MSBuildProjectFile)" Targets="Deploy" Condition="'$(TestStatus)'!='Failed'" /> 
    </Target> 

    For some reason, $(TestStatus) always seems to be set to "Unknown", whether unit tests succeed or fail. We've set the script to run unit tests simply by setting <RunTest>true</RunTest> in a PropertyGroup at the top of the script.

    Anyone have any ideas why this isn't working, or what we need to change to cause this build to fail and NOT run the deploy target when unit tests fail?

    YEX - http://yexley.net/bob/
    Tuesday, March 3, 2009 7:27 PM

Answers

  • Hello YEX,

      In addition to Jakob's,

      Here are two ways you can try:
     
          1.  Please use GetBuildProperties task to get the value of TestStatus before Deploy.

     
        <GetBuildProperties TeamFoundationServerUrl="$(TeamFoundationServerUrl)" BuildUri="$(BuildUri)">  
          <Output TaskParameter="TestStatus" PropertyName="TestStatus" /> 
        </GetBuildProperties> 
     

     
          2. check the TestSuccess property 

               Please use GetBuildProperties task to determine whether tests had passed

               Sample:

                
     
        <GetBuildProperties TeamFoundationServerUrl="$(TeamFoundationServerUrl)" BuildUri="$(BuildUri)">  
          <Output TaskParameter="TestSuccess" PropertyName="TestSuccess" /> 
        </GetBuildProperties> 


             
             From : http://social.msdn.microsoft.com/forums/en-US/tfsbuild/thread/5da2cf22-50fb-4c0d-8456-f7ed4f650b81

         The same way is in http://blogs.msdn.com/aaronhallberg/archive/2007/11/05/how-to-fail-a-build-when-tests-fail.aspx

       Good luck.

     
    Please mark the replies as answers if they help and unmark them if they provide no help
    • Edited by Hua Chen Thursday, March 5, 2009 8:20 AM Edit..
    • Marked as answer by Hua Chen Monday, March 9, 2009 6:02 AM
    Thursday, March 5, 2009 8:00 AM

All replies

  • Hi Bob,

    Assuming that you are on TFS 2008 SP1, you can use the TreatTestFailureAsBuildFailure property. Set this to true in order to fail the build if the tests fails.

    If you are on a previous version, check out this link for other ways to implement this functionality: 
    http://blogs.msdn.com/aaronhallberg/archive/2007/11/05/how-to-fail-a-build-when-tests-fail.aspx


    Regards
    /Jakob
    Tuesday, March 3, 2009 7:51 PM
  • I should have included that in my original message, sorry...we *are* on TFS 2008 SP1, and we do have TreatTestFailureAsBuildFailure set to True.
    YEX - http://yexley.net/bob/
    Tuesday, March 3, 2009 7:53 PM
  • Hello YEX,

      In addition to Jakob's,

      Here are two ways you can try:
     
          1.  Please use GetBuildProperties task to get the value of TestStatus before Deploy.

     
        <GetBuildProperties TeamFoundationServerUrl="$(TeamFoundationServerUrl)" BuildUri="$(BuildUri)">  
          <Output TaskParameter="TestStatus" PropertyName="TestStatus" /> 
        </GetBuildProperties> 
     

     
          2. check the TestSuccess property 

               Please use GetBuildProperties task to determine whether tests had passed

               Sample:

                
     
        <GetBuildProperties TeamFoundationServerUrl="$(TeamFoundationServerUrl)" BuildUri="$(BuildUri)">  
          <Output TaskParameter="TestSuccess" PropertyName="TestSuccess" /> 
        </GetBuildProperties> 


             
             From : http://social.msdn.microsoft.com/forums/en-US/tfsbuild/thread/5da2cf22-50fb-4c0d-8456-f7ed4f650b81

         The same way is in http://blogs.msdn.com/aaronhallberg/archive/2007/11/05/how-to-fail-a-build-when-tests-fail.aspx

       Good luck.

     
    Please mark the replies as answers if they help and unmark them if they provide no help
    • Edited by Hua Chen Thursday, March 5, 2009 8:20 AM Edit..
    • Marked as answer by Hua Chen Monday, March 9, 2009 6:02 AM
    Thursday, March 5, 2009 8:00 AM