public
Last active

Parallelize JUnit test suites.

  • Download Gist
ParallelSuite.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 33 34
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
 
import org.junit.runners.Suite;
import org.junit.runners.model.InitializationError;
import org.junit.runners.model.RunnerBuilder;
import org.junit.runners.model.RunnerScheduler;
 
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);
}
}
});
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.