首页 > 解决方案 > 如果我的 JUnit 测试没有它按预期工作,为什么要向我的 JUnit 测试添加 @RunWith 注释?

问题描述

使用 Spring Boot 时,我总是将其添加@SpringBootTest到我的测试类中,并且我的测试按预期工作。我想知道我也从添加中得到什么好处@RunWith(SpringRunner.class),因为整个互联网都在使用注释。

标签: javaspring-bootjunit

解决方案


@RunWith(SpringRunner.class)提供对加载 ApplicationContext 并将 bean@Autowired放入测试实例的支持。


推荐阅读