Using Spring mock objects
Posted on: February 3, 2011 at 12:00 AM
In this tutorial you will learn about the mock object

Using Mock objects

Mock Object is object that mimic/copy some real object behavior in a controlled way. It is implemented by some well known object interfaces with their dummy functionality. It is created to test the behavior of other object. It originally became popular by the junit team and the expert programmers/developers. The mock object simulate the behavior of real, complex object in unit testing.

 Mock is provided by the J2EE for each key interface on server side of j2ee specification. For example -

DelegatingServletInputStream- This object is used for the mock implementation of the ServletInputStream interface.

DelegatingServletOutputStream- This object is used for the mock implementation of the ServletOutputStream interface. Whenever required to check the content written by the output stream it can be used.

MockHttpServletRequest- This interface can be used for mock implementation of the HttpServletRequest interface. HttpServletRequest interface is commonly used in the application.

MockHttpServletResponse - It is used for the mock implementation of the HttpServletResponse interface.

MockHttpSession - This interface can be used for the mock implementation of the HttpServletSession interface.

The http request parameters holds very important value, which drive the main functionality of web components. The MockHttpServletRequest allows to set these parameter. For Example-

MockHttpServletRequest request= new MockHttpServletRequest("GET", "index.html");
    request.addParameter("Name", "James");
    request.addParameter("ID", "007");

Related Tags for Using Spring mock objects :



Advertisement null