Servlet unit test

前端 未结 3 386
鱼传尺愫
鱼传尺愫 2021-01-06 01:16

Currently I\'m using TestNG framework for testing application business logic, i added some Servlet classes recently.

How do I unit test these Servlet classes in Test

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-06 02:13

    I suggest that you move all of the business logic out of the servlet classes, into your own classes which you can test. That leaves the servlets just as glue between your business logic and the container, with nothing in them worth testing.

    The API classes such as HttpServletRequest, ServletConfig, etc, are prime targets for using a mocking framework of your choice (JMock, Mockito, etc), since they're all interfaces.

提交回复
热议问题