Phate
Phate

Reputation: 6612

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

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?

Upvotes: 16

Views: 11008

Answers (3)

Nikolas
Nikolas

Reputation: 44398

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.

Upvotes: 21

Kagan Coskun
Kagan Coskun

Reputation: 451

Please have a look at the maven definitions. The contents of the packages are detailed there. spring-boot-starter-test seems to be a superset of spring-boot-test since spring-boot-starter-test has dependency for 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

Upvotes: 3

robothy
robothy

Reputation: 1320

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

Upvotes: 4

Related Questions