Is there there any way to tell JUnit to run a specific test case multiple times with different data continuously before going on to the next test case?
First, create a TestNG class file and add all the required annotations. Identify that @Test annotation which you want to run multiple times. Once you identified the @Test annotation then design the test format as below. Here we use keyword named as invocationCount with some numeric value.
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.
Parameterized tests make it possible to run a test multiple times with different arguments. They are declared just like regular @Test methods but use the @ParameterizedTest annotation instead.
take a look to junit 4.4 theories:
import org.junit.Test; import org.junit.experimental.theories.*; import org.junit.runner.RunWith; @RunWith(Theories.class) public class PrimeTest { @Theory public void isPrime(int candidate) { // called with candidate=1, candidate=2, etc etc } public static @DataPoints int[] candidates = {1, 2, 3, 4, 5}; }
It sounds like that is a perfect candidate for parametrized tests.
But, basically, parametrized tests allow you to run the same set of tests on different data.
Here are some good blog posts about it:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With