3

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 をテストすることもできますが、組み込みサーバーなしでこのファイルをテストするためのより簡単な方法があるかどうかはわかりません。

4

1 に答える 1