You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Boot 2.5.4对应的JUnit版本及Junit5依赖配置问题

Spring Boot 2.5.4 JUnit相关问题解答

1. 默认适配的JUnit版本

Spring Boot 2.5.4版本的spring-boot-starter-test默认同时集成了两个JUnit大版本的核心依赖:

  • JUnit 5(Jupiter)版本:5.7.2
  • JUnit 4版本:4.13.2
    所有JUnit相关依赖的版本都由Spring Boot父依赖统一管理,只要引入spring-boot-starter-test无需额外指定版本号即可直接使用。

2. 使用JUnit 5是否需要额外添加Jupiter依赖

不需要额外添加。spring-boot-starter-test已经默认传递引入了JUnit 5运行所需的全部核心组件,包括junit-jupiter-api(编写测试用例的接口包)、junit-jupiter-engine(测试执行引擎)、junit-jupiter-params(参数化测试支持包)等,直接编写JUnit 5格式的测试用例即可运行。
如果你的项目不需要兼容JUnit 4格式的旧测试用例,可手动排除JUnit 4的兼容引擎减少不必要的依赖,Maven配置示例如下:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <scope>test</scope>
    <exclusions>
        <!-- 排除JUnit4兼容引擎,仅保留JUnit5支持 -->
        <exclusion>
            <groupId>org.junit.vintage</groupId>
            <artifactId>junit-vintage-engine</artifactId>
        </exclusion>
    </exclusions>
</dependency>

Gradle配置示例如下:

testImplementation('org.springframework.boot:spring-boot-starter-test') {
    exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}

内容的提问来源于stack exchange,提问作者Tohid Makari

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.03 11:39:03