Posts

Showing posts with the label junit

Junit Parallel Run Program

Below is the sample helper class needed to run parallel JUnit test: package default; 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 Parallelized extends Parameterized {       private static class ThreadPoolScheduler implements RunnerScheduler {     private ExecutorService executor;         public ThreadPoolScheduler() {       String threads = System.getProperty("junit.parallel.threads", "16");       int numThreads = Integer.parseInt(threads);       executor = Executors.newFixedThreadPool(numThreads);     }         @Override     public void finished() {       executor.shutdown();       try {         executor.awaitTermination(10, TimeUnit.MINUTES);       } catch (InterruptedException exc) {         throw new RuntimeException(exc);       }