views:

430

answers:

1

Setting up CI within Microsoft Team Foundation Server, I have a build that will build the solution and execute all of the unit tests within the solution.

Currently the build will show as partially succeded if the build is successful and an of the unit test fail. I would like to show the build as failed when a unit test fails.

Can anyone tell me if there is a way to accomplish this functionality?

Thank you in advance for your time spent on this quetion!

+3  A: 

If you have VS2008 SP1 installed on your build machine then you can simply add the following property to your TFSBuild.proj file:

<TreatTestFailureAsBuildFailure>true</TreatTestFailureAsBuildFailure>

If you don't have SP1 installed and you don't want to install it, then you can do it the old fashioned route as detailed here by the Dev Lead on the TFS Build team, Aaaron Hallberg:

  <Target Name="AfterTest">

    <!-- Refresh the build properties. -->
    <GetBuildProperties TeamFoundationServerUrl="$(TeamFoundationServerUrl)"
                        BuildUri="$(BuildUri)"
                        Condition=" '$(IsDesktopBuild)' != 'true' ">
      <Output TaskParameter="TestSuccess" PropertyName="TestSuccess" />
    </GetBuildProperties>

    <!-- Set CompilationStatus to Failed if TestSuccess is false. -->
    <SetBuildProperties TeamFoundationServerUrl="$(TeamFoundationServerUrl)"
                        BuildUri="$(BuildUri)"
                        CompilationStatus="Failed"
                        Condition=" '$(IsDesktopBuild)' != 'true' and '$(TestSuccess)' != 'true' ">

  </Target>
Martin Woodward
Once I installed Team Foundation Server 2008 SP1 and added the property you listed above in the "Additional Properties" section of the TFSBuild.proj it worked perfectly. Thank you for your help!!!
Sam