2009-09-16 156 views
5

在Microsoft Team Foundation Server中设置CI,我构建了一个构建解决方案并在解决方案中执行所有单元测试的构建。在单个单元测试失败时失败TFS构建

目前,如果构建成功并且单元测试失败,则构建将显示为部分成功。我想在单元测试失败时显示构建失败。

任何人都可以告诉我,如果有办法完成此功能?

回答

3

如果您在构建机器上安装VS2008 SP1中,那么你可以简单地将以下属性添加到您的TFSBuild.proj文件:

<TreatTestFailureAsBuildFailure>true</TreatTestFailureAsBuildFailure> 

如果您没有安装SP1和你不想要安装它,那么你就可以做到这一点的老式路线详细的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> 
+0

一旦我安装的Team Foundation Server 2008 SP1和TFSBuild.proj的“其他属性”节中添加你上面列出的财产它工作完美。 谢谢你的帮助! – Sam 2009-09-17 16:59:49