MSDN > 論壇首頁 > Team Foundation Server - Build Automation > Fail build when unit tests fail
發問發問
 

已答覆Fail build when unit tests fail

  • 2009年3月3日 下午 07:27Bob Yexley 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     包含代碼
    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/

解答

  • 2009年3月5日 上午 08:00Hua ChenMSFT, 版主使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     已答覆包含代碼
    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

所有回覆