qq_流浪_1
2018-04-24 22:30
问题如图,自动注入MockMvc失败
这是我可以运行的文件,希望对你有帮助...
package com.chengsluo.demo.controller; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import org.springframework.test.web.servlet.result.MockMvcResultMatchers; @RunWith(SpringRunner.class) @SpringBootTest @AutoConfigureMockMvc public class GrilControllerTest { @Autowired private MockMvc mockMvc; @Test public void girlsList() throws Exception { mockMvc.perform(MockMvcRequestBuilders.get("/girls")) .andExpect(MockMvcResultMatchers.status().isOk()); // .andExpect(MockMvcResultMatchers.status().string("213")); } }
Spring Boot进阶之Web进阶
104039 学习 · 393 问题
相似问题