是否存在在 Spring MVC 应用程序中使用 JUnit测试web.xml的方法?
我的项目根目录中有一个“web”文件夹。它包含一个WEB-INF/web.xml文件。
我这样写单元测试:
@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"));
}
}
未读取web.xml 。我确信这一点,因为当我在 web.xml 文件中出现语法错误时,测试仍然有效。
注意:我可以使用嵌入式 Tomcat 服务器来测试 web.xml,但我不知道是否存在一种更简单的方法来测试这个文件而无需嵌入式服务器。