Does it exist a way to test the web.xml with JUnit in a Spring MVC application?
I have a "web" folder at the root of my project. It contains a WEB-INF/web.xml file.
I write unit test like this:
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration("web")
@ContextConfiguration("path/to/mySpringApplicationContext.xml")
public class MyClassTest() extends AbstractMyClass {
//...
@Test
public void testController(){
mockMvc.perform(get("/path/to/myControllerURL"));
}
}
The web.xml is not read. I'm sure of that because when I do a syntax error in the web.xml file, the test still works.
Note: I could use an embedded Tomcat server to test the web.xml but I don't know if it exists a more simple way to test this file without an embedded server.
You're doing integration test of our code with spring framework. It does not include the java web container (usually tomcat or jetty), which are the ones concerned with web.xml. Please look at functionnal testing and tools like embedded jetty and selenium (these are not the only existing solutions).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With