Adam Warski
1 min readOct 9, 2023

--

I think a good general approach is to mock/stub/fake only the "integration points" with external systems, or in other words where the side effects happen.

And then, mocks are often the most convenient way to implement a fake, which would require a lot of noise (in the form of empty `???` methods) if implemented directly.

However, there might be a better solution to the problem: better infrastructure to create the fakes in the first place.

From my own back yard, that's exactly what was my goal when creating `SttpBackendStub` (https://sttp.softwaremill.com/en/stable/testing.html): a helper class to easily create a fake HTTP client.

Other usages of mocks are always in danger of causing the test to repeat the logic of the thing under test. And that's quite pointless.

(I know your `levelX` examples are oversimplified on purpose, but I'll pick on them anyway: any test which uses mocks to test their functionality would end up repeating the methods implementation. And copy-paste is bad ;) )

--

--

Adam Warski

Software engineer, Functional Programming and Scala enthusiast, SoftwareMill co-founder