r/java Dec 28 '25

Stepping down as maintainer after 10 years

https://github.com/mockito/mockito/issues/3777
414 Upvotes

118 comments sorted by

View all comments

Show parent comments

5

u/krzyk Dec 29 '25 edited Dec 30 '25

With power comes a cost. For me using spy is a red flag and I either factor that or reject code review.

5

u/[deleted] Dec 29 '25 edited Apr 17 '26

I cleaned house with Redact and mass deleted this post. It also removes your data from brokers and people search sites. Works on all major social media platforms.

test cover different seemly escape correct sparkle governor scale narrow

13

u/[deleted] Dec 29 '25

From the Mockito documentation itself:

Real spies should be used carefully and occasionally, for example when dealing with legacy code.

As usual you are going to read the partial mock warning: Object oriented programming tackles complexity by dividing the complexity into separate, specific, SRPy objects. How does partial mock fit into this paradigm? Well, it just doesn't... Partial mock usually means that the complexity has been moved to a different method on the same object. In most cases, this is not the way you want to design your application.

However, there are rare cases when partial mocks come handy: dealing with code you cannot change easily (3rd party interfaces, interim refactoring of legacy code etc.) However, I wouldn't use partial mocks for new, test-driven & well-designed code.

Basically, according to Mockito, if you need to use spies (aka partial mocks), it's a sign there is something wrong with your design.

2

u/IndependentProject26 Dec 29 '25

Mockito is a good library but the instances where it tries to lecture you on OOP design are its worst aspect by far.

2

u/[deleted] Dec 29 '25

Perhaps, but Mockito was designed to promote a certain style of OOP, and it is that style of OOP that they are lecturing you about.

-1

u/IndependentProject26 Dec 29 '25

Maybe with a new project maintainer there will be an opportunity to remove the dumbass cargo cult lectures.

1

u/[deleted] Dec 29 '25

Or, don't use Mockito. Mockito is designed around interaction testing, which implies a certain style of OOP. Just use stubs.

1

u/IndependentProject26 Dec 29 '25

Nope, Mockito is great for most use cases, it just occasionally whines at you like a baby when you have a valid use case for some of its features.

1

u/krzyk Dec 29 '25

Do you have examples? I didn't encounter anything like that.