Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 738
Phate Avatar asked Apr 09 '20 09:04

Phate


People also ask

What is the use of spring-boot-starter-test?

The spring-boot-starter-test is the primary starter dependency for testing our spring boot application. It contains the majority of libraries that are required for tests including JUnit Jupiter, Hamcrest, and Mockito.

What does spring-boot-starter-test contain?

The spring-boot-starter-test “Starter” (in the test scope ) contains the following provided libraries: JUnit 4: The de-facto standard for unit testing Java applications. Spring Test & Spring Boot Test: Utilities and integration test support for Spring Boot applications. AssertJ: A fluent assertion library.

Does spring-boot-starter-test include JUnit?

Spring Boot provides a number of useful tools for testing your application. The spring-boot-starter-parent POM provides JUnit, Hamcrest and Mockito “test” scope dependencies.

What is spring boot starter?

Spring Boot Starters are dependency descriptors that can be added under the <dependencies> section in pom. xml. There are around 50+ Spring Boot Starters for different Spring and related technologies. These starters give all the dependencies under a single name.


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

like image 142
Nikolas Charalambidis Avatar answered Sep 30 '22 04:09

Nikolas Charalambidis


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

like image 34
robothy Avatar answered Sep 30 '22 04:09

robothy