Mock frameworks can generate an ‘aha’ moment if you introduce them at the right moment. The evolution looks like this:
- Introduce unit testing as a concept.
- Walk through the basics of an xUnit framework.
- Introduce test driven development.
- Introduce fake objects or hand rolled stubs to substitute for things like DAOs.
- Use specialized mock object libraries like Shale mock JSF framework to build fake FacesContexts.
- Spring EasyMock or JMock on them to handle some nasty edge cases.
We choose EasyMock. Introducing it right up front would have been cognitive overload. Getting TDD installed is really more a journey than a simple prescriptive plan. TDD is about changing a core developer behavior in how they write code. So I saved the mock framework explanation for that moment where it elegantly solved the problem at hand.