I’m using the surefire maven plugin to run unit tests. My test class looks like this:
public class Test1 {
@org.junit.Test
public void testThatFails(){
Assert.assertTrue("false is never true", false);
}
}
When a test fails I expect to see the message “false is never true” that was associated with the AssertionError, but it’s not printed to the console. Instead I’m instructed to dig around in the surefire report directory and find it (which sucks).
Running com.example.Test1
Tests run: 4, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 5.799 sec <<< FAILURE!
Running com.example.Test2
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.016 sec
Running com.example.Test3
Tests run: 7, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.122 sec
Results :
Failed tests:
testThatFails(com.example.Test1)
Tests run: 12, Failures: 1, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] There are test failures.
Please refer to /<path-to-pom.xml>/target/surefire-reports for the individual test results.
After browsing to above directory I find the .txt file which contains the error message from my JUnit test, including the stack trace. I would like to see that same message and stack trace printed to the console during build (if it also gets added to a report file that would be great). Any ideas?
There is a surefire configuration which will specify whether to write the test reports to a file or to the console:
useFile. This defaults totrue.http://maven.apache.org/plugins/maven-surefire-plugin/test-mojo.html#useFile
With Maven, you can configure it to be
falseby including the following section in yourpom.xml:This will generate output like:
NOTE:
Using this configuration setting may break the reporting mechanisms of CI servers which show test failures. CI servers like TeamCity and Jenkins use the
surefire-reports.txtfiles to show detailed test failure information and it looks like this setting makes these reports not get generated. Unfortunately, I couldn’t find a way to make the report show in both console and get written to a file.