测试Service方法
@SpringBootTest
public class UserServiceTest{
@Autowired
private UserService userService;
@Test
public void findOne () throws Exception{
Assert.assertEquals("1002",userService.findOne());
}
}
测试Controller接口方法
@Runwith(SpringRunner.class)
@WebMvcTest(HelloController.class)
class HelloControllerTest{
@Autowired
private MockMvc mockMvc;
@Test
public void hello() throws Exception{
mockMvc.perform(MockMvcRequestBuilders.post("/hello").contentType(MediaType.APPLICATION_JSON)
.andExpect(status ().isOk())
.andDo(print ());
}
}