Skip to content

Continuous Integration Failing builds for failing tests

Marcus Fernstrom edited this page Jul 10, 2018 · 2 revisions

Fail? Or Unstable?

By default, when a Jenkins runs your tests (via ANT) and tests fail, your build will not be marked as “Failed” but as “Unstable”. If this is not what you want \-\- if you want failed tests to cause a build failure \-\- you need only make a small modification to your ANT build.

How to fail a build for failing tests

  1. add a “failureproperty” attribute to your mxunit task
  2. add a “fail” directive if failure property existsHere’s what it looks like, in code. This all happens in your “runTests” target
    <mxunittask ...[[omitted for brevity|]] testResultsSummary="my.summary" failureproperty="testsfailed">
    
    .....
    
    </mxunittask>
    
    ......
    
    <fail if="testsfailed" message="Failing the build because tests failed"/>
    </target>

Why this works

This works because the failure property will only be set if there are failures. If no failures occur, the property remains unset.

The fail directive’s “if” test will return true only if the property exists \-\- it does not matter whether it’s a boolean, whether it’s true, etc. I simply need exist. Consequently, fail will only run if the failureproperty is set due to failed tests

Clone this wiki locally