How to parameterize junit Test Suite

后端 未结 7 1891
梦毁少年i
梦毁少年i 2021-01-14 06:42

Is it possible to parameterize a TestSuite in junit 4 ?

For declaring a class as a test suite I need the annotation @RunWith(Suite.class), but the same

7条回答
  •  星月不相逢
    2021-01-14 07:14

    You're right: Both Suite and Parameterized are Runners and only one Runner may be used to run a test at a time. Standard JUnit 4 doesn't provide a combined Runner.

    You can either implement your own Runner or have a look at this ready-to-use library which provides a ParameterizedSuite Runner: https://github.com/PeterWippermann/parameterized-suite

    A parameterized test suite looks like this:

    @RunWith(ParameterizedSuite.class)
    @SuiteClasses({OneTest.class, TwoTest.class})
    public class MyParameterizedTestSuite {
        @Parameters(name = "Parameters are {0} and {1}")
        public static Object[] params() {
            return new Object[][] {{'A',1}, {'B',2}, {'C',3}};
        }
    

提交回复
热议问题