Unit testing with SpringBoot is simple.

First add dependencies

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
Copy the code

Notice that the unit test needs to add two annotations

@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class)  // Configure the startup class
Copy the code

If the DAO layer cannot be injected without the @runwith annotation, the unit tests must be written and executed in the module that has the startup class.