Dev Genius

Coding, Tutorials, News, UX, UI and much more related to development

Follow publication

Code Smell 30 — Mocking Business

Maximiliano Contieri
Dev Genius
Published in
2 min readNov 21, 2020

Photo by Syed Ahmad on Unsplash

Problems

  • Complexity
  • False sense of security.
  • Parallel/Duplicated objects (Real and Mocks)
  • Maintainability

Solutions

1. Mock just non-business entities.

2. Remove mock if its interface has too much behavior.

Sample Code

Wrong

Right

Detection

This is an architectural pattern. It will not be easy to create an automatic detection rule.

Exceptions

  • Mocking accidental problems (serialization, databases, APIs) is a very good practice to avoid coupling.

Tags

  • Abuser

Conclusion

Mocks, like many other test doubles are excellent tools. Choosing wisely 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

  • Faker

More info

The pesticide paradox. Every method you use to prevent or find bugs leaves a residue of subtler bugs against which those methods are ineffective.

Boris Beizer

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Published in Dev Genius

Coding, Tutorials, News, UX, UI and much more related to development

Written by Maximiliano Contieri

I’m a senior software engineer specialized in declarative designs. S.O.L.I.D. and agile methodologies fan. Maximilianocontieri.com

No responses yet

Write a response