roh*_*hit 3 java junit4 parameterized-tests spring-boot junitparams
我正在使用Spring Boot Starter Test编写JUnit测试用例。我很想使用JunitParamrunner,它可以方便地传递文件以进行参数化测试。基本上,它逐行从文件中读取数据,并且每行都调用一个测试用例。问题是同时使用SpringJUnit4ClassRunner和JUnitParamsRunner都需要传递@RunWith。我不知道该怎么做。谁能提供一些线索。
小智 5
@wjans提到的SpringClassRule是最好的解决方案,但是如果您的Spring版本小于4.2(最新的spring-boot-starter-test取决于spring版本4.1.7),则可以在测试构造函数中初始化上下文:
@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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3043 次 |
| 最近记录: |