0
votes

I have a multi-module Maven project. In the root pom.xml, I have added the following...

    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-surefire-plugin</artifactId>
      <version>2.18.1</version>
      <configuration>
        <parallel>methods</parallel>
        <threadCount>100</threadCount>
      </configuration>
    </plugin>

The command mvn test will cause each module to be built (if needed) and then the tests for that module will be run in parallel. Once all of the tests are done, Maven starts working on the next module. Maven will work on each module sequentially.

Inside, Eclipse IDE I can run TestNG against a suite called testng.xml. This file specifies that all packages should be run in parallel. This causes TestNG to run all test methods across all modules in parallel. This is exactly what I want to do but I am not sure how. A benefit of this is that all of the tests are run in 1 process and can share state between them. This state sharing speeds up the tests quite a lot. Note: I thought about using ant to execute a command but then I wasn't sure how to specify a classpath with the dependencies from the Maven repository.

mvn -T 8 test will allow for parallelism but because of dependencies between the modules I don't get all of the tests run in a parallel. I would be okay with running mvn compile test-compile -DskipTests=true first and then running mvn -T 8 test if this would run all of the tests in parallel.

Edit: The tests run are a mixture of unit and integration tests. With the option -Dgroups=, I can pick which set of tests are executed.

1
Have you tried a simple parrallel build ? Like mvn -T 8 test - KeatsPeeks
A parallel build should help though you cannot test a module until all it's dependencies have been built. - Peter Lawrey
Are those tests unit tests or integration tests...i would assume unit tests which means they are separated... - khmarbaise
@khmarbaise I updated the question to clarify. It doesn't seem to really matter what kind of test I am running. - Nathan

1 Answers

1
votes

In the last module to be built excluding Root, I added the following to the pom.xml.

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>exec-maven-plugin</artifactId>
  <version>1.4.0</version>
  <executions>
    <execution>
      <phase>test</phase>
      <goals>
        <goal>java</goal>
      </goals>
    </execution>
  </executions>
  <configuration>
    <classpathScope>test</classpathScope>
    <mainClass>org.testng.TestNG</mainClass>
  </configuration>
</plugin>

Then to run the tests, I use the following command:

mvn -DskipTests=true "-Dexec.args=testng.xml" test

The -DskipTests=true tells Maven to not execute the tests but the test phase tells Maven to build everything for the tests and run the above plugin. The "-Dexec.args=testng.xml" is an argument to TestNG in the above plugin configuration. Here's the contents of testng.xml.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >

<suite name="All" verbose="1" parallel="methods" thread-count="100">

  <test name="All">
    <packages>
      <package name=".*"/>
    </packages>
  </test>

</suite>

The parallel="methods" attribute allows TestNG to run in parallel each test method. The thread-count="100" attribute limits TestNG to running 100 threads. The package name=".*" attribute tells TestNG to run all tests in all packages.