Effective Software Testing

Share this post

Mocking frameworks vs mocks by hand

effectivesoftwaretesting.substack.com

Mocking frameworks vs mocks by hand

Maurício Aniche
Apr 10, 2022
2
Share this post

Mocking frameworks vs mocks by hand

effectivesoftwaretesting.substack.com

There was an interesting discussion on Twitter a few weeks ago on whether we should use mocking frameworks or not.

I asked to the author of the original post, why do you prefer hand-crafted stubs and fakes, Ted?

Twitter avatar for @mauricioaniche
Maurício Aniche @mauricioaniche
@jitterted @iamswardana Why do you prefer hand-crafted stubs and fakes, Ted?
7:28 PM ∙ Jan 4, 2022

Ted M. Young's response was: “The ease of using a tool to create them means you won't notice how complex the real thing has become. So, if it becomes difficult or tedious to create them by hand, that often points to interfaces or classes that have become too large, with too many responsibilities."

Twitter avatar for @jitterted
Ted M. Young #BlackLivesMatter #HexArch @jitterted
@mauricioaniche @iamswardana The ease of using a tool to create them means you won't notice how complex the real thing has become. So, if it becomes difficult or tedious to create them by hand, that often points to interfaces or classes that have become too large, with too many responsibilities.
8:03 PM ∙ Jan 4, 2022
13Likes2Retweets

Ted has a good point here. If you need complex mocking, then, maybe something is more complex than it should or needs to be.

I still support the use of a mocking framework, though. It's so much easier to use the Mockito's two lines of code to create a stub. But you should look at all the mock code and think "I could do this by hand if I wanted to". That's the key.

Share this post

Mocking frameworks vs mocks by hand

effectivesoftwaretesting.substack.com
Comments
TopNewCommunity

No posts

Ready for more?

© 2023 Maurício Aniche
Privacy ∙ Terms ∙ Collection notice
Start WritingGet the app
Substack is the home for great writing