【问题标题】:MockMVC always NullMockMVC 始终为 Null
【发布时间】:2020-09-10 14:32:26
【问题描述】:

MockMvc 始终为空!我还尝试了其他注释,就像在其他问题中描述的那样,但没有任何效果。

@ExtendWith(SpringExtension.class)
@WebMvcTest(controllers = HelpPageController.class)
public class HelpPageControllerTest {

    @Autowired
    private MockMvc mockMvc;

    @Test
    public void test() throws Exception {
        
        //other code
 
        ResultActions result = mockMvc.perform(MockMvcRequestBuilders.get("/help/manuals"));

       //other code

    }

【问题讨论】:

标签: spring testing null autowired mockmvc


【解决方案1】:

您应该添加@AutoConfigureMockMvc 注释,以便MockMvc 可以注入您的测试类。

【讨论】:

    猜你喜欢
    • 2020-04-19
    • 2020-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-14
    • 2022-01-20
    相关资源
    最近更新 更多