1 2 3 4 5 6 7 8 |
@Test public void testHello() throws Exception { mockMvc.perform(MockMvcRequestBuilders.get("/hello").accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(content().string(equalTo("Hello World!"))); } |
是因为静态导入的原因,只要导入:
1 2 3 |
import static org.hamcrest.Matchers.equalTo; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; |
然后就OK了。
from:https://blog.csdn.net/qq_21549989/article/details/78873229