Reputation: 151
I run a JUnit-based test suite in Maven, some 200 tests in total. Many produce Log4J DEBUG or ERROR lines, and I see them all mashed into a single long file in my surefire-reports directory.
I want to see all this output divided up by test, so I can discover what test produced what output. How can I do this?
Upvotes: 3
Views: 1446
Reputation: 32343
The most straightforward solution would be to a call to the following method to the beginning and end of each test:
static void printBeginning(PrintStream stream) {
String methodName = Thread.currentThread().getStackTrace()[0].getMethodName();
stream.format("---- Beginning Test: %s ----%n", methodName);
}
However, if you want to use surefire, the way to do this would be to write your own custom RunListener:
Basically, assign the RunListener in Maven, as in this documentation
<plugins>
[...]
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<properties>
<property>
<name>listener</name>
<value>com.mycompany.MyResultListener,com.mycompany.MyResultListener2</value>
</property>
</configuration>
</plugin>
[...]
</plugins>
Then the code will be run by Surefire.
You can read more about how to do this here: Using JUnit RunListener with Maven
Upvotes: 2