3

私はSpring ControllerのSpringベースのテストケースを書いています。私のコントローラーでは、このように「request.getSession().getServletContext().getRealPath("/myFolderName");」を使用しています。通常のリクエストでは問題なく動作しますが、MockHttpServletRequest のような単体テスト ケースでは、上記のメソッド呼び出しが null を返しています。MockHttpServletRequest の realPath を取得するにはどうすればよいですか。

ありがとう、プラニート。

4

1 に答える 1

2

By default MockHttpServletRequest acts as if root webapp folder is a classpath, therefore you should be able to use getRealPath() for classpath resources.

Alternatively, you can supply MockHttpServletRequest with MockServletContext, and MockServletContext can be configured with specific root folder for getRealPath(), etc.

于 2012-04-23T07:54:20.960 に答える