lundi 5 octobre 2020

MockMvc test not reach the Controller

I've tried a lot but unfortunately without success. I don't understand why I can't reach my controller.I have to run this test via the standalone setup because I don't have a SpringBoot project.

This is my test class:

@RunWith(SpringJUnit4ClassRunner.class)
public class HelpPageControllerTest {

    @Mock
    private HelpService helpService;

    private MockMvc mockMvc;

    @Before
    public void setUp() {
        MockitoAnnotations.initMocks(this);
        this.mockMvc = MockMvcBuilders
                .standaloneSetup(new HelpPageController())
                .build();
    }

    @Test
    public void justATest() throws Exception {
        ResultActions resultActions = mockMvc.perform(get("/help/manuals?lang=de"));
        resultActions.andExpect(status().isOk());
    }
}

This is my API that I'm trying to reach:

      @GetMapping("/help/manuals")
      public ResponseEntity<List<ManualResponseTO>> getManuals(@RequestParam String lang) {
       List<ManualResponseTO> manuals;
       manuals = this.helpService.getManuals(lang);
       return new ResponseEntity<>(manuals, HttpStatus.OK);
     }

Running the Test I get this answer:

enter image description here

When i go into the Debug-Mode I can see that the mockMvc is initialized, but I have also set a debug point in my controller, but this I can´t reach.

enter image description here

Aucun commentaire:

Enregistrer un commentaire