简体   繁体   English

如何在Maven测试运行输出中获取并行执行标识符

[英]How to get parallel execution identifier in Maven test run output

When using eg 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? 当使用例如mvn test -Tn运行Maven构建并行的n mvn test -Tn ,如何使Maven在其日志输出中添加并行测试运行程序的标识符呢? 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: 通过在MAVEN_OPTS变量中添加-Dorg.slf4j.simpleLogger.showThreadName=true ,很容易在日志输出中获取线程标识符(如https://maven.apache.org/maven-logging.html所述 ),但这并没有似乎不会影响surefire的输出,例如:

[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
-------------------------------------------------------

First by using -T ... you don't run the integration tests in parallel you run the building of the modules in parallel. 首先,通过使用-T ...您不会并行运行集成测试,而是并行运行模块的构建。

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. 此外,如果您使用的是maven-surefire-plugin,则说明操作有误,这是因为maven-surefire-plugin用于运行单元测试,而maven-failsafe-plugin用于集成测试。

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. 除此之外,您应该使用mvn ... verfiy来确保已运行pre-integration-testintegration-testpost-integration-test阶段。 If you call mvn .. integration-test the post-integration-test will not being executed. 如果您调用mvn .. integration-test ,则将不会执行post-integration-test

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. 此外,按照定义,集成测试无法并行化,因为它们通常使用资源,并且以其他方式耦合。.仅单元测试可以通过定义并行化,因为它们是独立的,等等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM