Adding JUnit Support to Spring Boot Application

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.


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,
  • Mockito-core,
  • Mockito JUnit Jupiter support,
  • json-path,
  • jackarta.xml.bind-api,
  • assertj-core,
  • hamcrest,
  • jsonassert,
  • spring-core,
  • spring-test,
  • xmlunit-core,
  • spring-boot-starter,
  • spring-boot-test,
  • spring-boot-test-autoconfigure.

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.