本文介绍了如何使JUnit测试用例并行执行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我发现jUnit中的测试用例是按顺序执行的,如何使它们并行执行?
I found the test cases inside jUnit are executed in sequence, how to make them execute in parallel?
推荐答案
Junit4使用 ParallelComputer 提供并行功能:
Junit4 provides parallel feature using ParallelComputer:
public class ParallelComputerTest {
@Test
public void test() {
Class[] cls={ParallelTest1.class,ParallelTest2.class };
//Parallel among classes
JUnitCore.runClasses(ParallelComputer.classes(), cls);
//Parallel among methods in a class
JUnitCore.runClasses(ParallelComputer.methods(), cls);
//Parallel all methods in all classes
JUnitCore.runClasses(new ParallelComputer(true, true), cls);
}
public static class ParallelTest1 {
@Test public void a(){}
@Test public void b(){}
}
public static class ParallelTest2 {
@Test public void a(){}
@Test public void b(){}
}
}
这篇关于如何使JUnit测试用例并行执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!