Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JUnit test web.xml with Spring MVC

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.

like image 286
Syl Avatar asked Jul 13 '26 16:07

Syl


1 Answers

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).

like image 115
Kartoch Avatar answered Jul 18 '26 07:07

Kartoch