1

I need to run my tests in parallel (JUnit5), but I don't now how to pass parameter into pom.xml as a maven goal.

For this moment I have such configuration for maven-surefire-plugin in my pom.xml, but I would like to pass junit.jupiter.execution.parallel.enabled = true as a maven goal, for example "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>

It can be useful to chose when to run tests in parallel, when to run them in the same thread.

How I can do it? Could you please help me?

  • Why from command line ? – khmarbaise May 04 '19 at 08:12
  • 1
    Possible duplicate of [Passing command line arguments from Maven as properties in pom.xml](https://stackoverflow.com/questions/7513319/passing-command-line-arguments-from-maven-as-properties-in-pom-xml) – Madhu Bhat May 04 '19 at 08:15
  • Please use one of the answers in the above question that I've commented. – Madhu Bhat May 04 '19 at 08:15
  • @khmarbaise sorry, probably I have explained bad. It seems, it will be correctly to say "as a maven goal" – user10028259 May 04 '19 at 08:21
  • Your comment confuses me much more ? Please explain in detail what you like to do and why you like to do and what kind of problem you like to solve... – khmarbaise May 04 '19 at 10:00

1 Answers1

2

I have found a solution.

In properties of pom.xml I set this:

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

Next, in plugin configuration I will set this:

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

Now I can run my test this way mvn -Dparallel=true testand set truewhen I want my tests run in parallel or false when I want they run in the same thread