How do I make Jenkins build fail when Maven unit tests fail?
You can add -Dmaven.test.failure.ignore=false
to the MAVEN_OPTS
if you click on Advanced button in the Build section of your Jenkins Job.
See Maven Surefire Plugin - surefire:test options for reference.
Use Text Finder plugin. Configure it to look for There are test failures
and downgrade the build to FAILED
Another hack that can be useful is to use groovy post-build to check and set test result.
e.g. this groovy gets build result, appends useful things to build description and sets build result to UNSTABLE in the case that there are no pass or fail but all tests skipped.
def currentBuild = Thread.currentThread().executable// must be run groovy post-build action AFTER harvest junit xml if you use junit xml test resultstestResult1 = currentBuild.testResultActioncurrentBuild.setDescription(currentBuild.getDescription() + "\n pass:"+testResult1.result.passCount.toString()+", fail:"+testResult1.result.failCount.toString()+", skip:"+testResult1.result.skipCount.toString())// if no pass, no fail all skip then set result to unstableif (testResult1.result.passCount == 0 && testResult1.result.failCount == 0 && testResult1.result.skipCount > 0) { currentBuild.result = hudson.model.Result.UNSTABLE}currentBuild.setDescription(currentBuild.getDescription() + "\n" + currentBuild.result.toString())def ws = manager.build.workspace.getRemote()myFile = new File(ws + "/VERSION.txt")desc = myFile.readLines()currentBuild.setDescription(currentBuild.getDescription() + "\n" + desc)