Vincent

"Now, if you're saying that you actually don't need to write any mock
implementation at all and that it could be generated for you "

For interfaces, such as the servlet API, that is what I am saying. In fact,
I am also saying that you can generate just the specific parts necessary to
a test at the scope of the individual test itself.

"- it has to use JDK 1.3, which is a problem as JDK 1.3 is far from being
used everywhere (maybe in 2 years time)"

Fair enough.

"generating a mock implementation on the fly works for simple cases only...
If you want to be convinced, look at my previous post when I was giving the
example on mocking HttpURLConnection."

I counter that *external mock implementation classes or mock containers*
either
work for simple cases only *or* end up in writing essentially a full class
or container.
:) I took a look at the HttpURLConnection you referenced and  I do not see
why you
cannot mock that "on the fly." If there are some additional outcomes in the
forms of exceptions or errors to which you expect the test subject to
respond
appropriately, then you just write additional tests for
those exception or errors and implement a quick anonymous class that
obliges. It actually encourages focused, finely grained unit tests.

"BTW, have you looked at the EasyMock project "

I took a look and it does have some merit. In reading the documentation,
however, I see that you cannot easily test the actual parameters that are
passed from the test subject to a method of the mock object (unless I missed
something), which is important for rigorous unit tests. Moreover, Alex made
a great point about complexity and my feeling is that if you are going to
negotiate a bit of complexity, you are better off doing it by learning about
some of the actual features of the Java language rather than the
complexities of yet another library, especially when the Java language
itself provides all the tools (if not better tools) the library does. As I
edit the testing patterns article I put together, I will show how the
ability to access references in the outside class from the inner testing
class makes the rigorous checking of method calls very easy and powerful.

"I would be very happy to have your vote on the several polls I have sent."

Ok, ok :). Thanks for the article draft feedback.

Tom




Reply via email to