Tutorial :how to get Tests run count on running same testCase for multiple times with different data



Question:

hi i want to run same testcase for multiple times with different data

for example if i run the same testcase for 3 times with different data it should show

Tests run: 3,failures : 0

when i tried am getting Tests run : 1 failures : 0 only any suggestions?

import org.junit.Test; import org.junit.experimental.theories.*; import org.junit.runner.RunWith; @RunWith(Theories.class) public class PrimeTest {

@Theory  @Test  public void isPrime(int candidate ){      System.out.println("candidate: "+ candidate );  }  public static @DataPoints int[] candidates = {1,2,3,4};  

}

Here testcase isPrime is running for 4 times means checking 4 testscenarios but in final result am getting testsRun : 1/1 failures :0 what i need is is should display as testsrun : 4/4 failures :0


Solution:1

You should pass the different data as parameter to the test and use a data provider to create the data. I little bit of test code would help to make more suggestions...


Solution:2

Probably you can use parameterized tests


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »