Migrating from JUnit4 to JUnit5 throws NullPointerException on @Autowired repositories

那年仲夏 提交于 2019-12-06 14:33:03

You're using the wrong @Test annotation.

When using the SpringExtension and JUnit Jupiter (JUnit 5), you have to use import org.junit.jupiter.api.Test; instead of import org.junit.Test;.

in the documentation it says:

If you are using JUnit 4, don’t forget to also add @RunWith(SpringRunner.class) to your test, otherwise the annotations will be ignored. If you are using JUnit 5, there’s no need to add the equivalent @ExtendWith(SpringExtension) as @SpringBootTest and the other @…Test annotations are already annotated with it.

Testing Spring Boot Applications

So try removing the @extendWith in your testclass

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!