web接口的测试
以下是MockMvc的使用代码。
@RunWith(SpringRunner.class) @SpringBootTest @ActiveProfiles("dev") public class Test { @Autowired private WebApplicationContext context; private MockMvc mvc; @Before public void init() { mvc = MockMvcBuilders.webAppContextSetup(context).build(); } @Test public void testGetMyInfo() throws Exception { mvc.perform(MockMvcRequestBuilders. get("/getmyinfo") // .param("name", "zhh") )// 参数 .andExpect(status().isOk())// 判断接收到的状态是否是200(静态导入) .andDo(print());// 打印请求和响应的详情 } }
其中有一个问题,为什么URL是/getmyinfo,为什么URL没有域名?
原来这个是本地调用,在Controller函数里打个断点,可以看到堆栈。
相关阅读
评论:
↓ 广告开始-头部带绿为生活 ↓
↑ 广告结束-尾部支持多点击 ↑