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

Viewed 4640

I a project I am handling, I see these dependencies defined:

<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>

But I can't understand why there are 2 artifacts for testing with Spring Boot, what is the difference between both of them? Maybe with the latter, I am also importing the former?

3 Answers

The spring-boot-starter-test is an aggregated "starter pack" for libraries using often together for testing in Spring applications.

As stated in the latest version reference documentation, the spring-boot-starter-test contains:

  • JUnit 5 (including the vintage engine for backward compatibility with JUnit 4)

  • Spring Test & Spring Boot Test - This is the spring-boot-test dependency)

  • AssertJ, Hamcrest, Mockito, JSONassert, and JsonPath.

You can remove the explicit definition of the spring-boot-test dependency.

From Spring Boot official reference:

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>>

Related