启动JUnit测试时弹出选择首选启动器的问题求助
解决Spring Boot项目在Eclipse中运行JUnit测试弹出启动器选择窗口的问题
直接选择对应启动器
弹出选择窗口时,选择JUnit 5(Spring Boot 2.7.x的spring-boot-starter-test默认集成JUnit Jupiter),同时勾选「Use this selection for all future launches of this type」,后续就不会再弹出该窗口。
验证项目JRE配置
- 右键项目 → 「Properties」→ 「Java Build Path」→ 「Libraries」
- 确认「JRE System Library」指向配置的jdk-11,若不是则点击「Edit」,选择已安装的jdk-11
刷新Maven依赖
- 右键项目 → 「Maven」→ 「Update Project」
- 勾选「Force Update of Snapshots/Releases」后点击「OK」,确保所有测试依赖完整下载
检查测试类注解正确性
确保测试类使用的是JUnit 5的注解:
import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; @SpringBootTest class DemoApplicationTests { @Test void contextLoads() { } }
注意@Test注解来自org.junit.jupiter.api包,而非JUnit 4的org.junit包。
内容的提问来源于stack exchange,提问作者KnowledgePath
相关产品推荐
相关产品推荐

