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
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 @mauricioanicheMaurício Aniche @mauricioaniche
@jitterted @iamswardana Why do you prefer hand-crafted stubs and fakes, Ted?

January 4th 2022

6 Likes

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 @jittertedTed 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.

January 4th 2022

2 Retweets13 Likes

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

Create your profile

0 subscriptions will be displayed on your profile (edit)

Skip for now

Only paid subscribers can comment on this post

Already a paid subscriber? Sign in

Check your email

For your security, we need to re-authenticate you.

Click the link we sent to , or click here to sign in.

TopNew

No posts

Ready for more?

© 2022 Maurício Aniche
Privacy ∙ Terms ∙ Collection notice
Publish on Substack Get the app
Substack is the home for great writing