Junit/TestNg junit 的 RunWith(Parameterized.class) 和 spring 的 @RunWith(SpringRunner.class) 冲突怎么办

木小白 · September 27, 2022 · Last by 木小白 replied at September 27, 2022 · 4074 hits

我用的 junit 做的自动化,公司里的开发 leader 给我搭建了一套能用 JdbcTemplate 的 spring 环境,jdbc 类上用的是@RunWith(SpringRunner.class),我单独用 junit 的 test 是可以访问到数据的,但是我用 junit 的 Parameterized 再执行 jdbctemplate 就显示空指针,这种情况怎么解决呀,求大佬

共收到 1 条回复 时间 点赞

解决了,是数据驱动的 runwith Parameterized 影响 spring 的自动注入了,@before方法里加了这两行就好了 TestContextManager testContextManager = new TestContextManager(getClass());
testContextManager.prepareTestInstance(this);

需要 Sign In 后方可回复, 如果你还没有账号请点击这里 Sign Up