Maven Surefire と並行して JUnit テストを実行することを扱うトピックをかなり見てきましたが、この特定の問題を扱う回答は見たことがありません。
要するに、テストメソッドは並行して実行されています (朗報です) が、プロップはスレッドを制限する役割を果たしません。最終的な目標は、Web ドライバーと appium の実行を並列化することですが、最初に可能なスレッドの合計を制御できるようにしたいと考えています。
以下のコード スニペットは、デモンストレーションのためにダミー プロジェクトからのものです。Apacheのドキュメントに従うと、以下よりもはるかに多くの機能があるようには見えません。
pom.xml
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<parallel>methods</parallel>
<threadCountMethods>2</threadCountMethods>
</configuration>
</plugin>
</plugins>
</build>
例Test.class
public class ExampleTest {
@Test
public void one() throws InterruptedException {
Thread.sleep(5000);
}
@Test
public void two() throws InterruptedException {
Thread.sleep(5000);
}
@Test
public void three() throws InterruptedException {
Thread.sleep(5000);
}
@Test
public void four() throws InterruptedException {
Thread.sleep(5000);
}
@Test
public void five() throws InterruptedException {
Thread.sleep(5000);
}
@Test
public void six() throws InterruptedException {
Thread.sleep(5000);
}
@Test
public void seven() throws InterruptedException {
Thread.sleep(5000);
}
@Test
public void eight() throws InterruptedException {
Thread.sleep(5000);
}
@Test
public void nine() throws InterruptedException {
Thread.sleep(5000);
}
@Test
public void ten() throws InterruptedException {
Thread.sleep(5000);
}
}
提供された pom 構成を使用してこのクラスを完全に実行するには、25 秒より少し長くかかると予想されます (一度に 2 つ実行すると、5 秒間 10 スリープします)。実際の実行時間は 5 秒強です。
Tests run: 10, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 5.022 sec - in ExampleTest
その threadCountMethods prop を変更しても、ランタイムには影響しません (threadCount prop に関係なく、すべてのメソッドが並行して実行されているように見えます)。
どんな意見でも大歓迎です。ありがとう!