Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ...

like image 437
maryoush Avatar asked Nov 28 '14 22:11

maryoush


People also ask

Can I have two @RunWith?

@RunWith(Parameterized. class) functionality. Adding Cucumber into the mix, uses @RunWith(Cucumber. class) and according to Junit you can't have multiple @RunWith options.

How do you RunWith in JUnit?

Create test suite using annotation @RunWithRight-click on the test source folder and select New -> Other -> JUnit -> JUnit Test Suite. Then, choose the name of the suite and the test classes that will be included in the suite and click Finish.

Which of the following you can use with @RunWith annotation?

We can run JUnit 5 tests with any older JUnit environment using the @RunWith annotation.


1 Answers

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);
}
like image 138
John B Avatar answered Oct 01 '22 20:10

John B