Excluding a non param test in parameterized test class

前端 未结 10 818
粉色の甜心
粉色の甜心 2020-12-02 19:32

Is there any annotation in JUnit to exclude a non param test in parameterized test class?

10条回答
  •  醉梦人生
    2020-12-02 20:21

    I was able to do something very similar to Matthew Madson answer and found it useful to create a Base Class to encapsulate setup and common helper functions between the single and param tests. This works without using Enclosed.class.

     @RunWith(Suite.class)
     @SuiteClasses({ComponentTest.ComponentParamTests.class, ComponentTest.ComponentSingleTests.class})
     public class ComponentTest {
    
        public static class TestBase {
            @Spy
            ...
            @Before
            ...
        }
    
        @RunWith(Parameterized.class)
        public static class ComponentParamTests extends TestBase{
            @Parameter
            ...
            @Parameters
            ...
            @Test
            ...
        }
        public static class ComponentSingleTests extends TestBase{
            @Test
            ...
        }
    }
    

提交回复
热议问题