4

I am using spring boot starter test for writing JUnit test cases. I would love to use JunitParamrunner which facilitates passing files for parameterized test.Basically it reads data from file line by line and for every line invoke a test case. The issue is to use both I need to pass @RunWith with both SpringJUnit4ClassRunner as well as JUnitParamsRunner. I am not able to figure out how to do that. Can any one provide some leads.

Panther
  • 3,312
  • 9
  • 27
  • 50
rohit
  • 862
  • 12
  • 26

2 Answers2

5

SpringClassRule mentioned by @wjans if the best solution, but if your Spring version is less than 4.2 (the latest spring-boot-starter-test depends on spring version 4.1.7), you can initialize the context in test constructor:

@ContextConfiguration(<your context location>)
@RunWith(JUnitParamsRunner.class)
public class ParameterizedTestWithSpring {

    private TestContextManager testContextManager;

    public ParametrizedTestWithSpring() throws Exception {
        this.testContextManager = new TestContextManager(getClass());
        this.testContextManager.prepareTestInstance(this);
    }

    // your test methods
Alex Borysov
  • 281
  • 1
  • 4
1

You can try to achieve your spring integration by using the SpringClassRule instead of the @RunWith annotation.

wjans
  • 10,009
  • 5
  • 32
  • 43