受JUnit實(shí)驗(yàn)啟發(fā)并行計(jì)算機(jī)我建立了自己的跑步者副等位套房和參數(shù)化跑步者。使用這些運(yùn)行程序,可以輕松地并行化測試套件和參數(shù)化測試。
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);
}
}
});
}}
參數(shù)化.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值中的一個平行*上課。
@RunWith(ParallelSuite.class)@SuiteClasses({ATest.class, BTest.class, CTest.class})public class ABCSuite {}