Search code examples
springjunitannotations

Multiple runwith for a junit test class


Does any one know how to tackle this.

@RunWith(SpringJUnit4ClassRunner.class)
@RunWith(Parametrized.class)

@ContextConfiguration("/META-INF/blah-spring-test.xml")
public class BlahTest
..

so i want to have a spring nature test and at the same time want to have it parameterized to avoid code duplication ...


Solution

  • You can't use two runners as it noted in the commented post. You should use the Parameterized runner as use Spring's TestContextManager to load the Spring context.

    @Before 
    public void before() throws Exception {
      new TestContextManager(getClass()).prepareTestInstance(this);
    }