I am trying to create Test class for Controller as below: Please note that we have created library for all repositories&domains (Using Spring DATA JPA) and added the dependency in actual application where UserController resides.
@RunWith(SpringRunner.class)
@WebMvcTest(value = UserController.class, secure = false)
public class UserControllerTest {
@MockBean
private UserService userService;
@Autowired
private MockMvc mvc;
@Test
public void testGetUsers() throws Exception {
when(userService.getAllUser()).thenReturn(new ArrayList<Organization>());
mvc.perform(get("/users")).andExpect(status().isOk());
}
}
When I tried to run this class, I got exception:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#4d41ba0f': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'entityManagerFactory' available
How to test spring Boot rest controllers with MockMvc by skipping repository classes ?