In this tutorial you will learn how to add JUnit support to your maven-based Spring Boot application.
The good news is that Spring Boot has a built-in support for JUnit. In fact, in most development environments, when you create a new Spring Boot project, it will already have a dependency for Unit Testing.
Spring Boot Starter Test Dependency
To add Unit Testing support to your maven-based Spring Boot application, add the following dependency to pom.xml file.
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency>
The above dependency will add to your project many useful libraries, including JUnit Jupiter, Mockito and Hamcrest. Let’s have a look at the complete list of compile dependencies that you will get by adding spring-boot-started-test dependency to your project.
- JUnit Jupiter,
- Mockito JUnit Jupiter support,
Once you add the spring-boot-started-test dependency to pom.xml file of your application, you should be ready to start writing your Unit Tests.
If you are interested to learn more about how to test your Java application with JUnit and Mockito, have a look at the list of tutorials in JUnit category.