I think that we're starting to learn, as a community, that mocks are a slippery slope that can cause more problems than they're worth, especially if used in excess.
I used to use mocking libraries, but I'm now arranging my architecture in a way that they aren't necessary anymore.
I use what you could call Hexagonal Architecture. Your core business logic has a class, but then any inbound or outbound calls go through an interface that's passed in. For testing, you can pass in interfaces that are either:
- mocked (mockito, easymock, etc)
- faked (create your own manual, simplistic implementation)
- emulated (moto, dynamodb-local, h2, mock-aws-java-sdk, fake embedded server etc.)
Any of these options can be used to implement or instrument your adapter classes. There's nothing wrong with mocking if it's done well, but I find it can easily be abused, so I try to avoid it.
Isn't mockito just a quick way to create fake, simplistic implementation? IMHO it's less work and less chances of faking the implementation incorrectly.
6
u/kag0 Nov 26 '20
Interesting to see mockito and vavr didn't make the list