public
Created

Parallelize JUnit parameterized tests.

  • Download Gist
ParallelParameterized.java
Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
 
import org.junit.runners.Parameterized;
import org.junit.runners.model.RunnerScheduler;
 
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);
}
}
});
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.