Maven Unit Tests and Continuous Integration Servers

11 Mar 2009

If you are running a Continuous Integration server such as Hudson, you'll want to consider routing your SureFire outputs to the console so that they'll appear in the build-report logs. If you leave SureFire at its default, it will output each test's success or failure to an individual test XML and TXT file, but those are likely not in an exposed directory on your CI server. If instead, you route the output to the console, it will get reported in your failure emails that your CI server is capable of sending.

Just pass the useFile=false parameter on the command line or set it in the plugin config section of your pom.xml.
mvn test -Dsurefire.useFile=false

Before:

-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.ambientideas.AppTest
Hello World! This is a JUnit test!
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.045 sec <<< FAILURE!
Results :
Failed tests:
testApp(com.ambientideas.AppTest)
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0

After:

-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.ambientideas.AppTest
Hello World! This is a JUnit test!
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.045 sec <<< FAILURE!
testApp(com.ambientideas.AppTest)  Time elapsed: 0.014 sec  <<< FAILURE!
junit.framework.AssertionFailedError
at junit.framework.Assert.fail(Assert.java:47)
at junit.framework.Assert.assertTrue(Assert.java:20)
at junit.framework.Assert.assertTrue(Assert.java:27)
at com.ambientideas.AppTest.testApp(AppTest.java:37)

Results :
Failed tests:
testApp(com.ambientideas.AppTest)
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0