详细信息

建议类型:无 Spring 处理方法调用

是否可在首选项配置:否

说明

Spring 使用 RequestMapping 注解定义的值将传入的 HTTP 请求映射到控制器处理方法。在 Spring Junit 测试中,如果 MockMvc.perform() 使用的值没有按照与任何 RequestMapping 注解匹配的方式进行配置,那么将不会调用任何处理方法。为确保调用正确的处理方法,应正确配置 MockMvc.perform() 使用的值。

示例

示例 1:

String pathSegment = ""; // UTA: Configure an appropriate parameter value since the tested method depends on it
ResultActions actions = mockMvc.perform(get("/form/" + pathSegment);

在本例中,perform() 使用与处理方法不匹配的路径“/form/”。

示例 2:

String pathSegment = "someValue";
ResultActions actions = mockMvc.perform(get("/form/" + pathSegment);

在更新的示例中设置了“pathSegment”的值,因此会在路径“/form/someValue”处调用处理方法。

  • No labels