Ask a questionAsk a question
 

AnswerFail build when unit tests fail

  • Tuesday, March 03, 2009 7:27 PMBob Yexley Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    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/

Answers

  • Thursday, March 05, 2009 8:00 AMHua ChenMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     AnswerHas Code
    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

All Replies