Code Smell 30 - Mocking Business
1 min read
Mocking is a great aid when testing behavior. Like with many other tools, we are abusing them.
False sense of security.
Parallel/Paired objects (Real and Mocks)
Mock just non-business entities.
Remove mock if its interface has too much behavior.
This is an architectural pattern. It will not be easy to create an automatic detection rule.
- Mocking accidental problems (serialization, databases, APIs) is a very good habit to avoid coupling.
Mocks, like many other test doubles, are magnificent tools. Choosing judiciously when to use them is an art.
Imagine a play in which each actor, instead of rehearsing with other actors, had to interact with 25 scriptwriters. The actors would never rehearse together. How would the result of the play be?
Also Known as
Photo by Syed Ahmad on Unsplash
The pesticide paradox. Every method you use to prevent or find bugs leaves a residue of subtler bugs against which those methods are ineffective.
This article is part of the CodeSmell Series.