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?
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.
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.
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.
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.
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>>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With