News for hackers. Stuff that matters.
Re:Mocking Is an Anti-Pattern by mehagar on Monday June 17, 2024 @11:59AM (#40707041)
I agree that if you need to write mocks, it's likely that your interfaces are poorly defined. This is one of the claimed benefits of test driven development - writing the tests first forces you to design the code in a way that cleanly separates modules so they can be tested.
Re:Mocking Is an Anti-Pattern by UK-Al05 on Monday June 17, 2024 @12:09PM (#40707205)
You have to mock/fake when modules call dependencies.

Your way means you only ever have siblings. With an orchestrator pulling results out of one module and pushing it into another.

Re:Mocking Is an Anti-Pattern by d0mine on Monday June 17, 2024 @03:10PM (#40709765)
Code that uses hexagonal architecture/dependency inversion requires less mocks in their tests.
Re:Mocking Is an Anti-Pattern by thiht on Monday June 17, 2024 @03:50PM (#40710217)
That’s… not true? No matter how you define your dependencies to inject, if you want to mock the dependencies you inject you have to mock them (it’s almost tautological), no matter if you use dependency inversion or not

Maybe you mean "less surface to mock", which is irrelevant if you generate your mocks automatically from the interface

Re:Mocking Is an Anti-Pattern by d0mine on Monday June 17, 2024 @05:14PM (#40711144)
> We can say that a Mock is a kind of spy, a spy is a kind of stub, and a stub is a kind of dummy. But a fake isn’t a kind of any of them. It’s a completely different kind of test double.

You define fakes in this case, not mocks https://blog.cleancoder.com/uncle-bob/2014/05/14/TheLittleMo...

Re:Mocking Is an Anti-Pattern by thiht on Tuesday June 18, 2024 @01:36AM (#40714366)
If you want. Replace mock by fake in my post and you get the same thing. It means I’m using fakes too when I’m not doing dependency inversion, so no mocks either

For what it’s worth, I find the distinction between mocks, fakes, spies, stubs, dummies and whatever completely useless in practice, the whole point is to control some data flows to test in isolation, it’s really all that matters.

Fun thing this kind of bikeshedding comes from Bob Martin, who famously has nothing worthwhile to show as an example of his actual work. Every time I read something from him, I get more and more convinced he’s a total fraud.

Re:Mocking Is an Anti-Pattern by d0mine on Tuesday June 18, 2024 @10:28AM (#40718265)
If words don't mean anything then of cause there is no difference. You might as well program in brainf*ck -- hey, it is turing complete, so same diff.

Personally, I like seeing "dummy" name passed into a function and understanding just from the name that no methods are expected to called on it during the test. Or seeing "fake_something " and understanding that a manual (perhaps test-specific) implementation is used. It is a minor point but such chunking is universally useful (there is enough stuff to keep track of).

My original point was that the architecture can facilitate so called classical unit tests over mocks (make the latter less necessary) https://martinfowler.com/articles/mocksArentStubs.html#Class...

Re:Mocking Is an Anti-Pattern by UK-Al05 on Saturday June 22, 2024 @08:26AM (#40758608)
I use that architecture. You still use mocks at the edges.