DualMock – an EasyMock extension

When I have been using easyMock Mock Objects for testing I often find it
helpful to intersperse expectations and test code, for example:

Doing this with easyMock requires me to validate and reset the object
frequently. I was thinking: What is stopping me from just calling
doing this:

Of course, the problem is that the object-under-test (in this case,
the server) and the test-code uses the same mock object instance. This
lead me to the following solution: Make two mock objects – one for the
expectiations and one for the actual code. Thus the name DualMock.
Here is a snippet of test code:

The code is not completely developed yet, as I have only used it marginally myself. Let me know through email or a comment if you’d like the code.

Dual Mock Test

Dual Mock Control

About Johannes Brodwall

Johannes is Principal Software Engineer in SopraSteria. In his spare time he likes to coach teams and developers on better coding, collaboration, planning and product understanding.
This entry was posted in Software Development. Bookmark the permalink.