如何将参数作为 Maven 目标传递给 pom.xml 以并行进行 运行 测试?

How to pass parameter into pom.xml as a maven goal to run tests in parallel?

我需要 运行 我的并行测试 (JUnit5),但我现在不知道如何将参数作为 Maven 目标传递给 pom.xml。

目前我的 pom.xml 中有这样的 maven-surefire-plugin 配置,但我想将 junit.jupiter.execution.parallel.enabled = true 作为 maven 目标传递,例如 "parallel=true"

          <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.1</version>
                <configuration>
                    <properties>
                        <configurationParameters>
                            junit.jupiter.execution.parallel.enabled = true
                            junit.jupiter.execution.parallel.mode.default = concurrent
                            junit.jupiter.execution.parallel.config.strategy=dynamic
                            junit.jupiter.extensions.autodetection.enabled = true
                        </configurationParameters>
                    </properties>
                </configuration>
            </plugin>

选择何时 运行 并行测试,何时 运行 它们在同一个线程中可能很有用。

我该怎么做?你能帮帮我吗?

我找到了解决办法。

pom.xml 的属性中,我设置为:

<properties>
   ...
   <parallel>false</parallel>
</properties>

接下来,在插件配置中我将这样设置:

           <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.1</version>
                <configuration>
                    <properties>
                        <configurationParameters>
                            junit.jupiter.execution.parallel.enabled = ${parallel}
                            ...
                        </configurationParameters>
                    </properties>
                </configuration>
            </plugin>

现在我可以 运行 我的测试方式 mvn -Dparallel=true test 并设置 true 当我想要并行测试时 运行 或 false 当我想要他们 运行 在同一个线程中