springBoot的测试类

来源:互联网 发布:讲课视频的软件 编辑:程序博客网 时间:2024/05/22 05:00
@RunWith(SpringRunner.class)@SpringBootTest(classes=SysconfigApplication.class)public class DictCtrollerTest {   @Autowired   private WebApplicationContext wac;   private MockMvc mockMvc;   @Before   public void setup() {      mockMvc = MockMvcBuilders.webAppContextSetup(wac).build();   }   /**    * 根据类型获取字典列表信息子查询的测试类用get【注意还有put:修改;delete;引用包:
    *   import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
**/ @Test public void QueryByDictType() throws Exception { String result = mockMvc.perform(get("/v1/dicts/sys_log_type") .accept(MediaType.APPLICATION_JSON_UTF8)) .andExpect(status().isOk()) .andReturn().getResponse().getContentAsString(); System.err.println(result); }}