Feel the Pain for Mock Frameworks

Mock frameworks can generate an ‘aha’ moment if you introduce them at the right moment. The evolution looks like this:

  1. Introduce unit testing as a concept.
  2. Walk through the basics of an xUnit framework.
  3. Introduce test driven development.
  4. Introduce fake objects or hand rolled stubs to substitute for things like DAOs.
  5. Use specialized mock object libraries like Shale mock JSF framework to build fake FacesContexts.
  6. 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.