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

标签 spring spring-boot maven spring-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 个 Artifact 用于 Spring Boot 测试,它们之间有什么区别?也许对于后者,我也在导入前者?

最佳答案

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

如最新版本引用 documentation 中所述, spring-boot-starter-test包含:

  • JUnit 5(包括与 JUnit 4 向后兼容的老式引擎)
  • Spring 测试和 Spring Boot 测试 - 这是 spring-boot-test依赖)
  • AssertJ、Hamcrest、Mockito、JSONassert 和 JsonPath。
  • 关于spring - spring-boot-test 与 spring-boot-starter-test 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61117933/

    相关文章:

    java - "Force update of snapshots/releases"- 这是什么意思

    jakarta-ee - 如何避免 WebappClassLoader.findResources 中的 NullPointerException?

    java - 无法将 Spring MVC 依赖项添加到 Maven 项目

    java - Hibernate/Spring - 在事务中回滚事务

    java - 当Mybatis同时使用WHERE IF DESC和LIMIT时,IDEA显示无法解析表 'LIMIT'

    java - 无法将数组传递给 Spring Boot Java

    java - Spring Boot - Spring security @ComponentScan 或 @Import

    java - 在进行查询的同一页面中显示结果的简单方法 - Spring App

    spring - 是否有任何 Spring Annotation 为字段(Mongo)设置默认值?

    java - ConstraintValidation 不适用于 Rest Api 请求