1. When creating a springboot project, the test framework will be automatically created
2. Right-click in the class that needs to be tested and click Generate, select Test
3. Add the @SpringBootTest annotation to the test class to declare that
the current class is in the Spring Boot container run in
4. Build the unit test code in the method
@SpringBootTest
@Transactional() // 单元测试不污染业务数据
class UserControllerTest {
@Autowired
private UserController userController;
@Test
void getAll() {
}
@Test
void add() {
UserInfo userInfo = new UserInfo();
userInfo.setName("Spring");
userInfo.setPassword("spring");
// 调用需要进行单元测试的方法
int result = userController.add(userInfo);
Assertions.assertEquals(1,result);
}
}