I want to test my servlet with http://www.easymock.org/
How do I write the Unit Testing Code?
I update my code with your responce.
I just used Google
You need to mock both HttpServletRequest
and HttpServletResponse
objects. There are existing implementations, easier to use compared to standard mocks.
Once you have request and response instances, you follow this pattern:
private final MyServlet servlet = new MyServlet();
@Test
public void testServlet() {
//given
MockHttpServletRequest req = //...
MockHttpServletResponse resp = //...
//when
servlet.service(req, resp);
//then
//verify response headers and body here
}