java - 如果我的 JUnit 测试没有它按预期工作,为什么要向我的 JUnit 测试添加 @RunWith 注释?
问题描述
使用 Spring Boot 时,我总是将其添加@SpringBootTest
到我的测试类中,并且我的测试按预期工作。我想知道我也从添加中得到什么好处@RunWith(SpringRunner.class)
,因为整个互联网都在使用注释。
解决方案
@RunWith(SpringRunner.class)
提供对加载 ApplicationContext 并将 bean@Autowired
放入测试实例的支持。
推荐阅读
- embedded-linux - 在 Qemu 上运行 buildroot 生成的覆盆子图像的问题
- r - 你如何在 R 中的用户定义函数中使用 any、if_any 或类似的东西?
- google-apps-script - Google Sheets Apps 脚本 - 移动设备上的输入框
- javascript - 使用 mongodb 自动填充输入
- excel - 更改事件中的 Excel VBA 参数不是可选错误
- automated-tests - 如何对 Slack App 进行自动化测试?
- c# - 如何保护 Blazor 服务器端的关键数据
- lora - Raspberry Pi Pico 发送 LoRa 消息
- c# - 将 Asp.Net Core Identity 系统用于用户帐户比我自己散列密码有什么优势?
- react-native - React-native:图像未渲染