添加Junit的起步依赖
springboot 2.4 自动使用junit5
编写测试类
@SpringBootTest
public class TextXxx
在Spring Boot项目中如果编写测试类则必须要在类上面添加@SpringBootTest
2.4.0版本使用Junit5,不需要加@Runwith
public interface IPersonService {
void savePerson();
}
@Service
public class PersonServiceImpl implements IPersonService {
@Override
public void savePerson() {
System.out.println("savePerson");
}
}
@SpringBootTest
class Demo02junitApplicationTests {
//查询所有的Person
@Autowired
private IPersonService service;
@Test
void contextLoads() {
service.savePerson();
}
}