From: Vincent M. <vm...@oc...> - 2001-09-06 10:25:54
|
----- Original Message ----- From: "Steve Freeman" <st...@m3...> To: "Vincent Massol" <vm...@oc...> Sent: Thursday, September 06, 2001 11:18 AM Subject: Re: [Mockobjects-java-users] What is the correct way of writing this test ? > > I am trying to find out if a generic way of writing mocks is possible and if > > a tool like MockMaker would be good enough. My question is thus: what would > > be the algorithm for generating a mock implementation of ServletOutputStream > > I'm sure that many mocks can be generated automatically, but not all. Unfortunately, output stream is a bad candidate because you shouldn't put too many restrictions on how the write methods are called. So, a stub implmenentation is as good as any and you can mess with the contents after the test. What's more interesting is to move to some kind of intermediate object as soon as possible so that you can put some structure in the code -- at which point a mock makes is more useful. > I'm not sure I agree with "many mocks can be generated automatically" ... I was just trying to convert my Cactus test cases into Mock Objects one to see how the test would differ. I also wanted to use generated mocks to see if it is usable. I started translating the first test ... and hit the ServletOutputStream issue ... I'm not sure I undestand the intermediate object you are referring to. Can you give an example on the test case I have written : { SampleServlet servlet = new SampleServlet(); MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); MockServletOutputStream output = new MockServletOutputStream(); output.setExpectedContent("<h1>A request</h1>"); response.setupOutputStream(output); servlet.doGet(request, response); output.verify(); } Thanks -Vincent |