My unit test fails when testing a controller. I am getting a 404 when expecting a 200 status code. I suppose the webAppContextSetup does not recognize controllers. Here is my code:
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = Application.class)
@WebAppConfiguration
@ContextConfiguration(classes = MyConfig.class)
public class MyControllerTest
{
@Before
public void setup()
{
MockitoAnnotations.initMocks(this);
mockMvc = MockMvcBuilders.webAppContextSetup(context).build();
}
mockMvc.perform(get("/locales?limit=1")).andExpect(status().isOk());
}
The message is "No mapping found for HTTP request with URI [/locales] in DispatcherServlet with name ''"
This works in the real application. Thanks.