1

Problem: When I run "mvn test" in the command line JUnit is not running my tests in parallel. Below is my entry into the pom for the surefire plugin to facilitate parallel. I am using Junit 4.12

                <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.19.1</version>
                <executions>
                    <execution>
                        <phase>test</phase>
                        <goals>
                            <goal>test</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <skip>false</skip>
                    <parallel>methods</parallel>
                    <threadCount>4</threadCount>
                </configuration>
            </plugin>

Essentially I have a series of dumb tests just to make sure threading is working correctly

@RunWith(Parameterized.class)
public class JunitTest {


Container container = new Container();

@Parameterized.Parameters
public static List<Object[]> data() {
    return Arrays.asList(new Object[10][0]);
}

@Test
public void test1(){
    Assert.assertTrue(container.something().childVal.equals("initial"));
    System.out.println("running test 1 on thread " + Thread.currentThread().getId());
    container.something().childVal = "dirty";

}
// basically several copies of this test after this

When the tests are ran I would expect that I would see different thread ID's being output.

adambsg
  • 131
  • 2
  • 9
  • 1
    check this question for more details http://stackoverflow.com/questions/423627/running-junit-tests-in-parallel-in-a-maven-build – Ammar Feb 18 '16 at 04:53
  • It works for me but I don't use RunWith annotation. My example is http://olyv-qa.blogspot.com/2017/04/run-junit-tests-in-parallel-using-maven.html – olyv Apr 02 '17 at 18:36
  • As for RunWith, from documentation: "As a prerequisite in JUnit tests, the JUnit runner should extend org.junit.runners.ParentRunner. If no runner is specified through the annotation @org.junit.runner.RunWith, the prerequisite is accomplished." – olyv Apr 02 '17 at 18:39
  • I think, it worked for me http://olyv-qa.blogspot.com/2017/04/run-junit-tests-in-parallel-using-maven.html – olyv Jun 29 '17 at 10:28

0 Answers0