i have parameterized junit tests which i would like to group the test functions so as to run one group in one test suite and the other group in another.
What i have tried is this:
TestClass:
@RunWith(Parameterized.class)
public class TestClass {
private int test;
public TestClass(int test){
this.test = test;
}
@Parameters
public static Collection<Object[]> data(){
return Arrays.asList(new Object[][]{{1},{1}});
}
@Test
@Category(A.class)
public void aTest(){
assertEquals(1, test);
}
@Test
@Category(B.class)
public void bTest(){
assertEquals(1, test);
}
}
Test suite:
@SuiteClasses({TestClass.class})
@RunWith(Categories.class)
@IncludeCategory(A.class)
public class Suite {
}
If I annotate the test class, rather than the methods, it works. However I want to categorize the functions rather then the test class and when I try that I get the following error:
Category annotations on Parameterized classes are not supported on individual methods
How can I get this to work (without switching to TestNG or another testing framework)?
You can create your own org.junit.runner.Runner to do that. It is not as hard as it looks. With your own runner you can build your own tree of test cases and JUnit will show it accordingly. In your case, your tree structure would reflect the category annotations.
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