当前位置: 动力学知识库 > 问答 > 编程问答 >

java - Junit 4.11 parameterized and categorized methods

问题描述:

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.

网友答案:

There is an issue for JUnit that will be fixed in JUnit 4.13.

分享给朋友:
您可能感兴趣的文章:
随机阅读: