在Maven构建中并行运行junit测试?我使用的是JUnit 4.4和Maven,还有大量的长期运行的集成测试。当涉及并行化测试套件时,有几种解决方案允许我在单个测试类中并行运行每个测试方法。但所有这些都要求我以一种或另一种方式改变测试。我真的认为在X线程中并行运行X不同的测试类将是一个更干净的解决方案。我有数百个测试,所以我不关心线程个别的测试类。有什么办法吗?
3 回答
HUWWW
TA贡献1874条经验 获得超12个赞
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.7.1</version> <configuration> <parallel>classes</parallel> <threadCount>5</threadCount> </configuration> </plugin> </plugins></build>
慕桂英4014372
TA贡献1871条经验 获得超13个赞
跃然一笑
TA贡献1826条经验 获得超6个赞
Par等位Suite.java
public class ParallelSuite extends Suite { public ParallelSuite(Class<?> klass, RunnerBuilder builder) throws InitializationError { super(klass, builder); setScheduler(new RunnerScheduler() { private final ExecutorService service = Executors.newFixedThreadPool(4); public void schedule(Runnable childStatement) { service.submit(childStatement); } public void finished() { try { service.shutdown(); service.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS); } catch (InterruptedException e) { e.printStackTrace(System.err); } } }); }}
参数化.java
public class ParallelParameterized extends Parameterized { public ParallelParameterized(Class<?> arg0) throws Throwable { super(arg0); setScheduler(new RunnerScheduler() { private final ExecutorService service = Executors.newFixedThreadPool(8); public void schedule(Runnable childStatement) { service.submit(childStatement); } public void finished() { try { service.shutdown(); service.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS); } catch (InterruptedException e) { e.printStackTrace(System.err); } } }); }}
@RunWith(ParallelSuite.class)@SuiteClasses({ATest.class, BTest.class, CTest.class})public class ABCSuite {}
添加回答
举报
0/150
提交
取消