Say No to Self-Shunt

My 3 cents on self-shunt testing pattern.

If you are not familiar with this pattern please read the following:

  1. The 'Self-Shunt' Unit Testing Pattern - original article by Michael Feathers,
  2. Self-Shunt blog post by Paul.

You will find much more about testing in my book
"Practical Unit Testing
with TestNG and Mockito"

There are two things that bother me about self-shunt.

  1. Your test class plays two roles: test and mock. This violates SRP (Single Responsibility Principle) which is a bad sign.
  2. It is something "temporary" which in the end should be refactored. Well, my experience tells me that "temporary" stuff tends to stay there forever. :)

And that is why I would not recommend it to anyone.

Mocking frameworks are so very convenient to use these days that I prefer to do it right (that is to mock it properly) the first time and don't see any need for a half-baked solution.

This used to be my blog. I moved to long time ago.


Please comment using