2 Must-Know Tricks of Unit Testing with Spring Boot
To improve the quality of unit testing of spring projects, you need to know about these tricks

For a java developer, unit testing is an integral part of our coding process. Unit testing allows you to pay attention to the correctness of the basic units of the software, and you can expose code defects in advance at the coding phase, and what’s more, it can make you more calm and confident in code refactoring.
Many people think unit testing is essential, but so many guys can’t do unit testing well, especially unit testing with spring boot. Do you have such a problem in a project with spring integration, Each time you execute a test case, you have to wait for the spring container to load the environment for more than ten seconds and that can be a nightmare for you who pursue efficiency.
Now there are two ways to solve your problem.
1. Use spring-boot-test-starter
spring-boot-test-starter(in the test scope)contains Junit5、Mockito、 Spring Testlibraries and we find these common libraries to be useful when writing tests. Testing with spring environment one of the major advantages is that dependency injection can make your code easier to unit test. Use spring-boot-test-starter, You can just load one or several Java beans you are interested in into the spring container and start testing directly without preparing all the environments. Here is a best practice.






