Reputation: 85
I have imported the following:
import org.springframework.test.web.servlet.result.MockMvcResultHandlers.*;
... for a controller test in a Spring Boot project but I cannot find the perform(get(,,,,))
method.
Any suggestions?
Upvotes: 3
Views: 5150
Reputation: 67
Add comments.
import library
Import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
import static org.springframework.test.web.servlet.setup.MockMvcBuilders.*;
Check this [link][1].
[1]: https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/test/web/servlet/MockMvc.html
Upvotes: 3
Reputation: 47935
The perform()
method is a static method on: org.springframework.test.web.servlet.request.MockMvcRequestBuilders
.
Here's the full signature:
public static MockHttpServletRequestBuilder get(URI uri) {
return new MockHttpServletRequestBuilder(HttpMethod.GET, uri);
}
And it is used like so:
@Autowired
private MockMvc mockMvc;
mockMvc.perform(MockMvcRequestBuilders.get("/some/uri"))
.andExpect(MockMvcResultMatchers.status().isOk());
Upvotes: 2