1.service测试
在类上双击右键--》go to --->test自动创建测试类
在类上添加注解
@RunWith(SpringRunner.class)
@SpringBootTest
依赖注入
@Autowired
private UserServiceImpl userService;
使用
Assert.assertEquals(new Integer(1),new Integer(user.getId()));
进行判断
2.Controller api测试
在类上双击右键--》go to --->test自动创建测试类
需要多添加 AutoConfigureMockMvc 注解
@RunWith(SpringRunner.class)
@SpringBootTest
@AutoConfigureMockMvc
注入
@Autowired
private MockMvc mvc;
添加url以及结果判断
mvc.perform(MockMvcRequestBuilders.get("/user/list")).andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.content().string("abc"));