SpringMVCを使用するアプリケーションの単体テストをいくつか書きたかったのです。Springホームページのマニュアルページを読みましたhttp://static.springsource.org/spring/docs/current/spring-framework-reference/html/testing.html
。このSpringテストフレームワークは本当に役立つようです。
しかし、ここに質問があります:
@ContextConfiguration
1.私がそれを正しく理解している場合、私が使用する必要があるようにテストに注釈のいずれかを使用するには@RunWith(SpringJUnit4ClassRunner.class)
?しかし、2つのランナーを使用することは可能ですか(おそらくそうではありません)、私は通常のオブジェクトをモックするためにmockitoを使用しているので、Springランナーとmockitoを使用できるかどうか疑問に思いました。
2.を使用してxmlコンテキストファイルをロードすることについて質問があります@ContextConfiguration
。.xmlファイルを持っていますがsrc/main/webapp/WEB-INF/spring
、どうすればそれらをロードできますContextConfiguration
か?私は試した
@ContextConfiguration(locations="/webapp/WEB-INF/spring/root-context.xml")
@ContextConfiguration(locations="webapp/WEB-INF/spring/root-context.xml")
@ContextConfiguration(locations="/WEB-INF/spring/root-context.xml")
@ContextConfiguration(locations="WEB-INF/spring/root-context.xml")
@ContextConfiguration(locations="/src/main/webapp/WEB-INF/spring/root-context.xml")
@ContextConfiguration(locations="src/main/webapp/WEB-INF/spring/root-context.xml")
しかし、私はいつも得ますclass path resource [some_path] cannot be opened because it does not exist
。それでは、どのパスを使用すればよいのでしょうか。
編集:2番目の問題は、WEB-INFがクラスパスにないことでした。これが、spring-context.xmlの場所を教えてくれたトピックです。