spring-boot-test 和 spring-boot-starter-test 有什么区别?

what's the difference between spring-boot-test vs spring-boot-starter-test?

我正在处理一个项目,我看到定义了这些依赖项:

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <groupId>org.junit.vintage</groupId>
                <artifactId>junit-vintage-engine</artifactId>
            </exclusion>
            <exclusion>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

但是我不明白为什么有 2 个用于 Spring Boot 测试的工件,它们之间有什么区别?也许对于后者,我也在导入前者?

来自Spring Boot官方参考:

Spring Boot provides a number of utilities and annotations to help when testing your application. Test support is provided by two modules: spring-boot-test contains core items, and spring-boot-test-autoconfigure supports auto-configuration for tests.

more details>>

spring-boot-starter-test 是一个聚合的“入门包”,用于在 Spring 应用程序中经常一起使用的库进行测试。

如最新版本参考 documentation 所述,spring-boot-starter-test 包含:

  • JUnit 5(包括用于向后兼容 JUnit 4 的老式引擎)

  • Spring 测试 & Spring 启动测试 - 这是 spring-boot-test 依赖)

  • AssertJ、Hamcrest、Mockito、JSONassert 和 JsonPath。

您可以删除 spring-boot-test 依赖项的显式定义。

请查看 Maven 定义。包的内容在那里有详细说明。 spring-boot-starter-test 似乎是 spring-boot-test 的超集,因为 spring-boot-starter-test 依赖于 spring-boot-test .

https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-test/2.2.5.RELEASE

https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-test/2.2.5.RELEASE