Is there a way around @RunWith in JUnit?

I have one main test class (A) and another (B) that extends from it.

A has an annotation @RunWith(SpringJUnit4ClassRunner.class)to initialize it. I need to use annotation @RunWith(JUnitParamsRunner.class)on B.

But it seems that I can not do both. Is there a way I can parameterize test suites without annotation @RunWith?

Another solution is to use

testContextManager = new TestContextManager(AbstractInvoiceCreationModuleTest.class);
testContextManager.prepareTestInstance(this);

But I can not write this in the method @BeforeClass, because it is static and does not allow using it. I do not want to write the above code snippet in the method @Before, since the class will be initialized before each test method. And many test classes extend from A.

What can be done?

+4
3
+1

Spring ​​ JUnit @Rule Spring 4.2.

http://docs.spring.io/spring/docs/4.2.x/spring-framework-reference/html/integration-testing.html#testcontext-junit4-rules

:

// Optionally specify a non-Spring Runner via @RunWith(...)
@ContextConfiguration
public class IntegrationTest {

   @ClassRule
   public static final SpringClassRule SPRING_CLASS_RULE = new SpringClassRule();

   @Rule
   public final SpringMethodRule springMethodRule = new SpringMethodRule();

   @Test
   public void testMethod() {
      // execute test logic...
   }
}
+2

(Spring test runners), , .

0

Source: https://habr.com/ru/post/1534788/


All Articles