问题:当我在命令行中运行“mvn test”时,JUnit没有并行运行我的测试。下面是我进入pom的surefire插件以方便并行。我正在使用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>
基本上我有一系列愚蠢的测试只是为了确保线程正常工作
@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
当测试运行时,我希望我会看到输出不同的线程ID。