Unit Testing Rest Services with Spring Boot and JUnit
Unit Testing Rest Services with Spring Boot and JUnit
The reason is because you are mocking your controller. This is not necessary when you have @WebMvcTest(UserResourceController.class)
This should work.
@ContextConfiguration(classes={TestSystemConfig.class})
@RunWith(SpringRunner.class)
@WebMvcTest(UserResourceController.class)
public class UserResourceControllerTests {
@Autowired
private MockMvc mvc;
@Test
public void getUser() throws Exception {
mvc.perform(get(/api/users/1)
.with(user(pere.peris@gmail.com).password(password))
.contentType(APPLICATION_JSON))
.andExpect(status().isOk());
}
}