Creating a mock HttpServletRequest out of a url string?

后端 未结 5 1152
别跟我提以往
别跟我提以往 2020-12-04 21:04

I have a service that does some work on an HttpServletRequest object, specifically using the request.getParameterMap and request.getParameter to construct an object.

5条回答
  •  误落风尘
    2020-12-04 21:33

    You would generally test these sorts of things in an integration test, which actually connects to a service. To do a unit test, you should test the objects used by your servlet's doGet/doPost methods.

    In general you don't want to have much code in your servlet methods, you would want to create a bean class to handle operations and pass your own objects to it and not servlet API objects.

提交回复
热议问题