Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to let the build fail, when any JUnit test fails?

We use latest Hudson version together with ANT scripts to build our projects. We have installed several extra plugins (like pmd, findbugs.. etc) to let a build get unstable, when a number of errors occur. Since we usually are above those numbers concerning pmd most builds are unstable.

So sometimes it happens, that we notice too late, that there are several JUnit tests failing, since we are used to it, that the build is unstable. I know that increasing the number of allowed errors in PMD script would be a (temporary) solution as well as fixing most of them, but we would prefer a solution, where we could let a build just fail, when a junit test fails, or at least give it a special custom state, so we automatically get informed, that something is wrong with our tests.

Do you know any solution for this problem?

like image 309
crusam Avatar asked Jan 28 '26 02:01

crusam


1 Answers

Try this:

<junit haltonfailure="no" failureproperty="test.failed" ... >
...
</junit>
<fail message="Test failure detected, check test results." if="test.failed" />

This will run all tests, and will cause the build to fail if one test fails. Alternatively, if you want to just stop the build after a test fails, change the haltonfailure property to yes.

like image 74
Ben Green Avatar answered Jan 30 '26 14:01

Ben Green



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!