I've created a basic integration test using the standard MockMvc setup for my Spring Boot / Thymeleaf application. My simple test is just to verify that the About page of the website loads. When I run the test and verify status, I get a "java.lang.AssertionError: Status expected:<200> but was:<404>" error
I've tried several different ways to create the MockMvc object. Most of my other attempts left the mockMvc object null, but I can verify that it's being created and is attempting to load the page.
Here's my controller:
@RequestMapping(value = "/about", method = RequestMethod.GET)
public String loadAbout(Model model) {
LOGGER.trace("Loading about page");
return "about";
}
Here's my test class:
@Test(groups = { "sboot" })
@WebMvcTest
@WebAppConfiguration
@ImportAutoConfiguration(ThymeleafAutoConfiguration.class)
@ActiveProfiles("dev")
@ContextConfiguration(classes = { WebSecurityConfig.class, WebMvcConfig.class, DatabaseConfiguration.class })
public class UserIT extends AbstractTestNGSpringContextTests {
@Autowired
private WebApplicationContext wac;
private MockMvc mockMvc;
@Test
public void AboutPage() throws Exception {
mockMvc = MockMvcBuilders.webAppContextSetup(wac).build();
mockMvc.perform(get("/about"))
.andExpect(status().isOk());
}
}
This is the error message I'm seeing:
10:00:32.382 [DEBUG] [TestEventLogger] Gradle suite > Gradle test > com.eshrsys.sboot.test.integration.UserIT.AboutPage FAILED
10:00:32.382 [DEBUG] [TestEventLogger] java.lang.AssertionError: Status expected:<200> but was:<404>
10:00:32.382 [DEBUG] [TestEventLogger] at org.springframework.test.util.AssertionErrors.fail(AssertionErrors.java:55)