yas*_*yas 5 spring-mvc mockito springmockito
我怎样才能在mockito,spring mvc环境中为boolean编写测试用例
例如,如下面的响应
MockHttpServletResponse:
Status = 200
Error message = null
Headers = {Content-Type=[application/json;charset=UTF-8]}
Content type = application/json;charset=UTF-8
Body = {"name":"myName","DOB":"12345"}
Forwarded URL = null
Redirected URL = null
Cookies = []
Run Code Online (Sandbox Code Playgroud)
我们会写测试用例,比如
mockMvc.perform(get("/reqMapping/methodName"))
.andExpect(status().isOk())
.andExpect(content().contentType("application/json;charset=UTF-8"))
.andExpect(jsonPath("$.name",comparesEqualTo("myName");
.andExpect(jsonPath("$.DOB",comparesEqualTo("12345");
Run Code Online (Sandbox Code Playgroud)
对?但是,当我们得到响应时,请遵循
MockHttpServletResponse:
Status = 200
Error message = null
Headers = {Content-Type=[application/json;charset=UTF-8]}
Content type = application/json;charset=UTF-8
**Body = true**
Forwarded URL = null
Redirected URL = null
Cookies = []
Run Code Online (Sandbox Code Playgroud)
我该如何编写测试用例?
mockMvc.perform(get("/reqMapping/methodName"))
.andExpect(status().isOk())
.andExpect(content().contentType("application/json;charset=UTF-8"))
.andExpect(???);
Run Code Online (Sandbox Code Playgroud)
您需要做的就是以下内容:
mockMvc.perform(get("/reqMapping/methodName"))
.andExpect(status().isOk())
.andExpect(content().contentType("application/json;charset=UTF-8"))
.andExpect(content().string("true");
Run Code Online (Sandbox Code Playgroud)
以上代码的肉是(返回)的string方法.ContentResultMatcherscontent()
这是相关的javadoc
| 归档时间: |
|
| 查看次数: |
2768 次 |
| 最近记录: |