Junit 4.11 parameterized and classified methods

I have parameterized junit tests that I would like to group test functions in order to run one group in one test suite and another in another.

What I tried:

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 comment on a test class, not methods, it works. However, I want to classify functions, not a test class, and when I try, 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)?

+4
source share
2 answers

org.junit.runner.Runner, . , . , JUnit . .

+3

JUnit, ​​ JUnit 4.13.

+2

All Articles