views:

49

answers:

2

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

A: 

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...

Arne Burmeister
hi arne below is the sample code here the testcase is running for 4 times but in report it is showing as runtests : 1/1 failure: 0 what i need is runtests : 4/4 failure: 0 so that you can easily find the failure case...import org.junit.Test;import org.junit.experimental.theories.*;import org.junit.runner.RunWith;/** * @author * */@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}; }
sundeep
A: 

Probably you can use parameterized tests

sateesh
am able to run the testcase for multiple times but am getting tests run as 1 only i should get full count
sundeep
but why would that matter ? Can you please clarify how the statement like number of tests run is 4 (say) instead of 1 would help ? Do you want to draw the implication that more number of tests imply better testing, which I think is incorrect. Things like statement,branch, and conditional coverage, give a better idea of how good your unit test covers the code base.
sateesh