【问题标题】:How to pass parameter into pom.xml as a maven goal to run tests in parallel?如何将参数传递到 pom.xml 作为 maven 目标以并行运行测试?
【发布时间】:2019-05-04 18:11:27
【问题描述】:

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

目前,我的 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>

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

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

【问题讨论】:

  • 为什么从命令行?
  • 请使用我评论过的上述问题中的一个答案。
  • @khmarbaise 抱歉,我可能解释得不好。看来,说“作为一个 Maven 目标”是正确的
  • 你的评论让我更加困惑?请详细说明你喜欢做什么,为什么喜欢做,想解决什么样的问题...

标签: java maven pom.xml junit5


【解决方案1】:

我找到了解决办法。

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

【讨论】:

    猜你喜欢
    • 2022-11-23
    • 2023-03-10
    • 2016-06-16
    • 1970-01-01
    • 2011-11-22
    • 2019-07-17
    • 2018-03-28
    • 1970-01-01
    • 2012-11-23
    相关资源
    最近更新 更多