Unit Testing Using Spring Boot
Learn how to write a test using the @SpringBootTest annotation and why it should not be used for unit testing.
We'll cover the following...
When we create an application using Spring Boot, we get the springboot-starter-test
dependency that comes with Mockito and AssertJ as testing libraries. We also automatically get a test file with the @SpringBootTest
annotation.
Unit testing should not be done using Spring Boot. The main purpose of unit testing is to test a method or class. However, @SpringBootTest
loads the entire context, which makes the test lengthy and defeats the purpose of unit testing. This feature of Spring Boot should be used in integration testing where we test across multiple layers. ...