选择被测试的类的类名,按住shift+Ctrl+T,自动生成一个测试类的模板,然后按以下方式填充内容:
1.针对controller层:
public class ControllerTest extends RfidBaseTest {
private static final String PREFIX = "/前缀路径";
@Test
public void queryList() throws Exception {
String param = //输入的参数;
mvc.perform(
MockMvcRequestBuilders.post(PREFIX + "/路径")
.contentType(APPLICATION_JSON_VALUE)
.accept(APPLICATION_JSON_VALUE)
.content(param)
.headers(HEADERS)
)
.andExpect(MockMvcResultMatchers.status().isOk());
}
2.针对Service或Mapper层:
public class IServiceTest extends RfidBaseTest{
@Autowired
IService service;
@Test
public void queryList() {
PageBean<Dto> query=new PageBean<>();
Dto