cover-img

Code Smell 30 - Mocking Business

26 November, 2022

0

0

0

Mocking is a great aid when testing behavior. Like with many other tools, we are abusing them.

Problems

Complexity

False safety sensation.

Parallel 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.

Also Known as

Faker

More Info

Credits

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.

Boris Beizer
This article is part of the CodeSmell Series.

0

0

0

Maxi Contieri

Buenos Aires, Argentina

🎓Learn something new every day.📆 💻CS software engineer 👷coding👨🏽‍🏫teaching ✍🏾writing 🎨Software Design 🏢SOLID 🌉TDD 👴Legacy 💩Code Smells

More Articles

Showwcase is a professional tech network with over 0 users from over 150 countries. We assist tech professionals in showcasing their unique skills through dedicated profiles and connect them with top global companies for career opportunities.

© Copyright 2024. Showcase Creators Inc. All rights reserved.