Over Mocking

Over Mocking

Paul Pagel

September 07, 2006

I’ve noticed using more mocks lately. Instead of using them sparingly for controlling services which are not instrumental to what I am testing, I’m essentially using them as a way to isolate what I’m testing.

This has me noticing a side effect I’m not entirely comfortable with. To use the mock, I need to be able to have the mock in the production code, which means I need to inject an abstraction of the mock (dynamic mocks will do that for you).

So, the side effect is long parameter lists, specifically in constructors. Everything takes almost all the objects it uses. Then, to create the production objects are factories.

I’m using many more factories than I would without mass mocking. I’m not sure if this is a good use of dependency decoupling and factory building as design techniques, or if this is a symptom of over design and tightly coupling the mocks to the tests, making it more difficult to change the tests without changing the interface the mock is implementing. Thoughts?

Paul Pagel

Chairman, Founder, and President

Paul Pagel founded 8th Light in 2006, and has been a driving force in the software development community ever since. He has grown 8th Light from a small consultancy into a brand that is recognized by software developers worldwide.