Stop Using Mocking Libraries

Boost Code Quality Without Mocks

Alex Maher
2 min readSep 3, 2024
Boost Code Quality Without Mocks

Hey there! Ever used mocking libraries and found your tests breaking a lot? You’re not alone. It’s time to try something else.

What’s Wrong With Mocking Libraries?

Mocking libraries, like Mockito and MOCK, help us make fake versions of our code for tests. Sounds good, right? But these mocks often make our tests weak. Let’s see why.

The Hidden Risks

New developers often use too many mocks. This makes tests tied to little details, so they break easily. Also, mocking code can look messy. Sometimes, you feel like you’re writing more test code than actual code.

The Alternative: Fakes

So, what’s the better way? Use fakes. A fake is a simple version of a real object. It acts like the real thing, but it’s easier to handle. Let’s see why fakes are better.

Why Fakes Make Sense

Fakes copy what your real code does. Unlike mocks, fakes act more like the real thing. Think of it as a practice run — your code works with a real-looking part, without the problems.

How to Implement a Fake

--

--

Alex Maher
Alex Maher

Written by Alex Maher

.NET C# dev with 10+ yrs exp, self-taught & passionate web developer. Sharing tips & experiences in C# and web dev.

Responses (24)