Article From:


Need to introduce dependency

    <!-- When the development is introduced, the package --> will not be loaded when it is released.< scope> test< /scope>< /dependency>< dependEncy>< groupId> org.springframework< /groupId>< artifactId> spriNg-test< /artifactId>< version> 4.0.2.RELEASE< /version>< scope≫ test< /scope>< /dependency>

View Code

You can also write the base class, then the concrete business class inherit, you can also directly. Here I will standardize, first write the base class.

BaseTest.javaAs follows,@Before and @After annotations are provided by JUnit, meaning is written in the notes of the code:

write specific test classes

After writing the test base class, you can start writing the real unit test. Here is a simple example:

We can see that a method of unit testing can be run directly in IDEA, without compiling a project and starting a server to achieve functional testing of the business code, and the convenience of it.



SpringBootJunit and SpringMVC are basically similar, and only need to change some configuration.

Add dependency


write the test base class


Leave a Reply

Your email address will not be published. Required fields are marked *