Java 使用MockMvc时,正文为空
它总是给空的身体: 当我使用TestRestTemplate时,它工作得很好。但是,当我使用MockMvc和@MockBean时,它总是给出空输出。我还使用了Java 使用MockMvc时,正文为空,java,spring-boot,testing,mockmvc,Java,Spring Boot,Testing,Mockmvc,它总是给空的身体: 当我使用TestRestTemplate时,它工作得很好。但是,当我使用MockMvc和@MockBean时,它总是给出空输出。我还使用了com.gargoylesoftware.htmlunit.WebClient。但是,这也给了空的身体。我不知道发生了什么事。请帮忙。是版本问题还是我做错了什么? Spring boot版本:1.5.10您的控制器执行customerService方法。对吗?那你就得把这个方法存根 <pre> <code> Mo
com.gargoylesoftware.htmlunit.WebClient
。但是,这也给了空的身体。我不知道发生了什么事。请帮忙。是版本问题还是我做错了什么?
Spring boot版本:1.5.10您的控制器执行customerService方法。对吗?那你就得把这个方法存根
<pre>
<code>
MockHttpServletRequest:
HTTP Method = GET
Request URI = /customer/get/vikas
Parameters = {}
Headers = {}
MockHttpServletResponse:
Status = 200
Error message = null
Headers = {}
Content type = null
Body =
Forwarded URL = null Redirected URL = null
Cookies = []
</code>
</pre>
<pre>
<code>
MockHttpServletRequest:
HTTP Method = GET
Request URI = /customer/get/vikas
Parameters = {}
Headers = {}
MockHttpServletResponse:
Status = 200
Error message = null
Headers = {}
Content type = null
Body =
Forwarded URL = null Redirected URL = null
Cookies = []
</code>
</pre>
@Test
public void testMethod() throws Exception {
when(customerService.doSomething())
.thenReturn(mockResult); // you need to make this code
this.mockMvc.perform(get("/url"))
.andExpect(someThing);
}