I have a JUnit5 integration test project where I'm running the test classes in parallel. My problem is that my log messages are being mixed together in the junit XML report generated after the test class finishes executing. This makes it difficult to debug the root cause of a failure because sometimes the xml containing a failed test won't even have a system-out section for the failed test because another xml report grabbed them already.
This xml report is showing the system-out from 3 out of 4 threads. How do I get this so that it is only showing the correct thread in the xml report?
<testcase name="beforeEachFailure" classname="tests.BeforeEachTests" time="32.962">
<failure type="java.lang.AssertionError">
<![CDATA[
java.lang.AssertionError
at tests.BeforeEachTests.beforeEach(BeforeEachTests.java:19)
]]>
</failure>
<system-out>
<![CDATA[
10:45:23.227 [Thread-0] INFO StaticUtil - Sleep for 3s
10:45:23.228 [Thread-0] INFO BeforeAllTests - continue doing a thing
10:45:26.228 [Thread-1] INFO StaticUtil - Sleep for 3s
10:45:29.228 [Thread-1] INFO StaticUtil - Sleep for 3s
10:45:32.229 [Thread-1] INFO StaticUtil - Sleep for 3s
10:45:32.229 [Thread-1] INFO TestTests - half the things done
10:45:35.230 [Thread-2] INFO StaticUtil - Sleep for 3s
10:45:38.231 [Thread-2] INFO StaticUtil - Sleep for 3s
]]>
</system-out>
</testcase>
Configuration for maven-surefire-plugin:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
<configuration>
<statelessTestsetReporter implementation="org.apache.maven.plugin.surefire.extensions.junit5.JUnit5Xml30StatelessReporter">
<version>3.0</version>
<usePhrasedTestCaseMethodName>true</usePhrasedTestCaseMethodName>
</statelessTestsetReporter>
<consoleOutputReporter implementation="org.apache.maven.plugin.surefire.extensions.junit5.JUnit5ConsoleOutputReporter">
<encoding>UTF-8</encoding>
</consoleOutputReporter>
<statelessTestsetInfoReporter implementation="org.apache.maven.plugin.surefire.extensions.junit5.JUnit5StatelessTestsetInfoReporter">
<usePhrasedClassNameInTestCaseSummary>true</usePhrasedClassNameInTestCaseSummary>
</statelessTestsetInfoReporter>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<reportsDirectory>${basedir}/target/surefire-reports</reportsDirectory>
<includes>
<include>**/*Test*.java</include>
</includes>
<properties>
<configurationParameters>
junit.jupiter.execution.parallel.enabled = true
junit.jupiter.execution.parallel.mode.default = same_thread
junit.jupiter.execution.parallel.mode.classes.default = concurrent
junit.jupiter.execution.parallel.config.strategy = fixed
junit.jupiter.execution.parallel.config.fixed.parallelism = 4
</configurationParameters>
</properties>
</configuration>
</plugin>
</plugins>
log4j2 configuration:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
<Appenders>
<Console name="Console">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %c{1} - %msg%n"/>
</Console>
</Appenders>
<Loggers>
<Root level="trace">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>