The
EasyMock package provides an easy way to use
MockObjects for given interfaces in the
JavaLanguage.
EasyMock 1.1 is available (2004-05-03), as well as a first release of the
EasyMock Class Extension that was contributed by Joel Shellman, Henri Tremblay, and Chad Woolley.
For more information, see
http://easymock.org
The
EasyMock mailing list on yahoogroups is at
http://groups.yahoo.com/group/easymock
A
DotNet port of
EasyMock is available at
http://easymock.net
When I create a JDBC Mock
Connection and the code under test uses this to create a Prepared
Statement, both of these packages have me specify, in advance, the exact string of the SQL statement passed to prepareStatement(). There could be a lot of variation in that SQL, capitalization, whitespace, even order of columns, that I'd rather not specify in the code. What I
would like to do is verify that, when the Mock
Prepared
Statement is invoked, that the parameters are passed in the same order as the table columns are specified. What's the easiest way to accomplish this?
Use ParameterMatcher in EasyMock 1.0.
Both the
EasyMock and
MockObject packages work from the basis that you define the behavior and expected use of the mock objects, let the code-under-test access them, and then ask them if the actual use met the predefined expectations. To some degree, this seems backwards to me. I have to define the behavior and use of the Result
Set, then define the behavior and use of the Prepared
Statement that will return the Result
Set, and then define the behavior and use of the Connection that will return the Prepared
Statement. I'd rather define the behavior, let the code-under-test access them, and then test the actual use against expectations. Not only is that easier for me to read, but it lets me easily do conditional testing based on some criteria.
Setting expectations first has a big advantage: If actual and expected behavior differ, the mock object may provide failure information as early as possible. This simplifies finding and fixing errors.
Other dynamic approaches to
MockObjects:
[
CategoryMockObjects]