Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make JUnit test cases execute in parallel? [duplicate]

Tags:

junit

Possible Duplicate:
Running junit tests in parallel?

I found the test cases inside jUnit are executed in sequence, how to make them execute in parallel?

like image 758
user496949 Avatar asked Apr 03 '11 10:04

user496949


People also ask

How do I run parallel execution in JUnit?

By enabling parallel execution, the JUnit engine starts using the ForkJoin thread pool. Next, we need to add a configuration to utilize this thread pool. We need to choose a parallelization strategy. JUnit provides two implementations (dynamic and fixed) and a custom option to create our implementation.

Is parallel execution possible in JUnit?

Yes, You can. Show activity on this post. JUnit Toolbox provides JUnit runners for parallel execution of tests.

How do you run the same test case multiple times in JUnit?

The easiest (as in least amount of new code required) way to do this is to run the test as a parametrized test (annotate with an @RunWith(Parameterized. class) and add a method to provide 10 empty parameters). That way the framework will run the test 10 times.

How do you repeat a test in JUnit?

@RepeatedTest annotation is used to repeat a test for a specific number of times. The basic syntax of @RepeatedTest is as follows: The annotation @RepeatedTest is used for a test method instead of the annotation @Test. A number is passed as the input parameter of the annotation.


1 Answers

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(){}      }   }  
like image 130
卢声远 Shengyuan Lu Avatar answered Sep 18 '22 16:09

卢声远 Shengyuan Lu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!