开发者

Can't make the TFS build fail after custom logic runs

开发者 https://www.devze.com 2023-01-26 14:13 出处:网络
I\'ve written some custom logic to get NUnit tests into a TFS build. It\'s all working beautifully except when the tests don\'t pass the build is partially succeeded rather than failed. Anyone know ho

I've written some custom logic to get NUnit tests into a TFS build. It's all working beautifully except when the tests don't pass the build is partially succeeded rather than failed. Anyone know how I can tell it to fail?

Here's what I'm trying:

<BuildStep Message="Integration Tests Passed"
   Condition="$(TestsResult)  == 'True'"
   TeamFoundationServerUrl="$(TeamFoundationServerUrl)"
   BuildUri="$(BuildUri)"
   Id="$(IntegrationTestsStepId)"
   Status="Succeeded" />
<BuildStep Message="Integration Tests FAILED"
   Condition="$(TestsResult) != 'True'"
   TeamFoundationServerUrl="$(TeamFoundationServerUrl)"
   BuildUri="$(BuildUri)"
   Id="$(IntegrationTestsStepId)"
   Status="Failed"
   CompilationStatus="Failed"
   TestStatus="Failed"/>
<!-- If NUnit failed开发者_如何学C it's time to error out -->
<Error Condition="$(TestsResult) != 'True'" Text="Unit Tests Failed" />


It was the <SetBuildProperties> that was the magic:

    <SetBuildProperties TeamFoundationServerUrl="$(TeamFoundationServerUrl)"
                        BuildUri="$(BuildUri)"
                        CompilationStatus="Failed"
                        TestStatus="Failed"
                        Condition="'$(TestsResult)' != 'True'">
</SetBuildProperties>


<Error Condition="'$(TestsResult)'!='True'" Text="Smoke Tests Failed" />
<SetBuildProperties TeamFoundationServerUrl="$(TeamFoundationServerUrl)"
                        BuildUri="$(BuildUri)"
                        CompilationStatus="Succeeded"
                        TestStatus="Succeeded"
                        Condition="'$(TestsResult)' != 'False'">
</SetBuildProperties>

I think it boils down to needing to signal the CompilationStatus and the TestStatus


This is the default behaviour for Unit Tests in Team Build. We use MStest rather than nUnit so this might not work but you are setting $(TestResult) so it should be OK. If you have VS2008 SP1 installed on your build server you can add the following line to your TfsBuild.proj (in the additional properties section) and it should fail the build

<TreatTestFailureAsBuildFailure>true</TreatTestFailureAsBuildFailure>

0

精彩评论

暂无评论...
验证码 换一张
取 消