What would you think about a MIMOCK?

The use of mocking in [TB]DD allways makes me feel slightly bad. I just don't like the idea of using an object in my tests, that is potentially pretending a behaviour, that the implementation of the 'real thing' might not provide. And: I suspect not being the only one... But the alternative, i.e. using the real dependency, has several disadvantages:

Tests tend to be slow:
Often a dependent service, object, etc., requires some amount of time to be set up in regular test runs. This is particular bad, if you're commited to a test driven approach. This might not be significant while executing only a few tests, but very annoying for a large test suite.
Tracing errors is more difficult:
Mocking provides a natural way of decoupling tests. If for example a large service framework is represented by a mock object, a test failure clearly is not to be found in the dependency! If the real service framework is used instead, any kind of unpredictable errors could occur due to e.g. networking problems or any other thing.
So far about the disadvantages of not using mocks. So why hesitate? Now my problem with this is the following: A mock object is just another artifact created by a human being--a code snippet. And we all know, programmers introduce between one and three bugs every thousand lines of code. Thus a mock setup may be wrong, just with any other piece of code. Now what could be a solution to this? This evening I had a vision of a new approacht to mocking, I thought could be named:



Mimocking

Mimocking is a creation out of the word mimic and mocking. The basic idea is:

A mimock should use the 'real thing', e.g. the real service our artifact under test depends on, if executed for the first time. It may then generate a derived mock out of the used interface and store it as a cached value object. This object could then be reused over and over again, as long as it is used in the same manner AND the dependent object, library or service (the real thing ;-) stays the same--hence is not updated.

Please post your feedback, since I think this to be a feasible approach. Why not make an open source project out of this...


About this entry