title: How to Run Unit Test in Parallel Across All Modules Using Maven?
body: <p>I have a multi-module Maven project.  In the root pom.xml, I have added the following...</p>
  
  <pre><code>    &lt;plugin&gt;
        &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
        &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
        &lt;version&gt;2.18.1&lt;/version&gt;
        &lt;configuration&gt;
          &lt;parallel&gt;methods&lt;/parallel&gt;
          &lt;threadCount&gt;100&lt;/threadCount&gt;
        &lt;/configuration&gt;
      &lt;/plugin&gt;
  </code></pre>
  
  <p>The command <code>mvn test</code> 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.</p>
  
  <p>Inside, Eclipse IDE I can run TestNG against a suite called <code>testng.xml</code>.  This file specifies that all packages should be run in parallel.  This causes TestNG to run all test methods across <strong>all</strong> 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.</p>
  
  <p><code>mvn -T 8 test</code> 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 <code>mvn compile test-compile -DskipTests=true</code> first and then running <code>mvn -T 8 test</code> if this would run all of the tests in parallel.</p>
  
  <p><strong>Edit:</strong> The tests run are a mixture of unit and integration tests.  With the option <code>-Dgroups=</code>, I can pick which set of tests are executed.</p>