测试类
/**
* @author Nick
* @version V1.0.0
* @Date 2017/11/23 20:22
* @description 测试类
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = ProducerServiceApplication.class)
@WebAppConfiguration
public class ApplicationTests {
@Autowired
private WebApplicationContext context;
private MockMvc mvc;
/**
* 测试Controller
*/
@Test
public void controllerTest() throws Exception {
mvc = MockMvcBuilders.webAppContextSetup(context).build();
mvc.perform(MockMvcRequestBuilders.get("/pwp/api")
.contentType(MediaType.APPLICATION_JSON_UTF8)
.param("name", "nickwu")
.accept(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.status().isOk())
.andDo(MockMvcResultHandlers.print())
.andExpect(MockMvcResultMatchers.content().string(Matchers.containsString("Success_nickwu")));
}
}