Details

Recommendation type: No Spring handler method invocations

Configurable: No

Description

Spring maps incoming HTTP requests to controller handler methods using the values defined by the RequestMapping annotations. In a Spring JUnit test, no handler methods will be called if the values used by MockMvc.perform() are not configured in a way that matches any RequestMapping annotations. To ensure that the proper handler method is called, configure the values used by MockMvc.perform() correctly.

Examples

Example 1:

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

In this example, perform() will use the path "/form/", which will not match the handler method.

Example 2:

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

In this updated example, the value of "pathSegment" is set, so the handler method will be invoked at the path "/form/someValue".

  • No labels