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

Pha*_*ate 11 spring spring-test maven spring-boot

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

<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>
Run Code Online (Sandbox Code Playgroud)

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

Nik*_*las 11

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

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

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

  • Spring 测试和 Spring Boot 测试 - 这是spring-boot-test依赖项)

  • AssertJ、Hamcrest、Mockito、JSONassert 和 JsonPath。