在 Microsoft Team Foundation Server 中设置 CI,我有一个构建,它将构建解决方案并在解决方案中执行所有单元测试。
当前,如果构建成功并且单元测试失败,则构建将显示为部分成功。当单元测试失败时,我想将构建显示为失败。
谁能告诉我是否有办法完成此功能?
最佳答案
如果您的构建机器上安装了 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>
关于unit-testing - 在单个单元测试失败时失败 TFS 构建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1434041/