Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get parallel execution identifier in Maven test run output

When using e.g. mvn test -Tn to run Maven builds parallelized n-fold, how can I get Maven to prefix its log output with the identifier of the parallel test runner? Currently the log output looks like:

[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] -------------------------------------------------------

which makes it very difficult to tell which instance logged what

I would like it to show some kind of parallel execution (thread, process, whatever) identifier in the logs, like:

[1][INFO] -------------------------------------------------------
[1][INFO]  T E S T S
[2][INFO] -------------------------------------------------------
[2][INFO]  T E S T S
[2][INFO] -------------------------------------------------------
[1][INFO] -------------------------------------------------------

It's easy enough to get thread identifiers in the log output by adding -Dorg.slf4j.simpleLogger.showThreadName=true to MAVEN_OPTS envionment variable (as described at https://maven.apache.org/maven-logging.html) but this doesn't seem to affect surefire output, for example:

[BuilderThread 1] [INFO] Surefire report directory: C:\redacted\path\to\module2\target\surefire-reports
[BuilderThread 0] [INFO] Nothing to compile - all classes are up to date
[BuilderThread 0] [INFO]
[BuilderThread 0] [INFO] --- maven-surefire-plugin:2.18.1:test (default-test) @ module1 ---
[BuilderThread 0] [INFO] Surefire report directory: C:\redacted\path\to\module1\target\surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
like image 209
Tuure Laurinolli Avatar asked Oct 29 '22 17:10

Tuure Laurinolli


1 Answers

First by using -T ... you don't run the integration tests in parallel you run the building of the modules in parallel.

Furthermore if you are using maven-surefire-plugin you are doing something wrong, cause maven-surefire-plugin is for running unit tests whereas maven-failsafe-plugin is for integration test.

To parallelize the tests itself you should check the docs how to do that.

Apart from that you should use mvn ... verfiy to be sure that the pre-integration-test, integration-test and post-integration-test phase have run. If you call mvn .. integration-test the post-integration-test will not being executed.

Furthermore by definition integration tests can't be parallized cause they usually use resources, are coupled in other ways..only unit tests can be parallized by definition cause they are independent etc.

like image 194
khmarbaise Avatar answered Nov 02 '22 23:11

khmarbaise