Mocking/Dependency injection in Elixir and Hexagonal Architecture

If I pass a stub ( instead of a mock ) to a function, am I still not adhering to his vision?

Ok, I need to watch my terminology - what I should have said:

Those doubles are those false objects you don’t like creating.

Gerard Meszaros actually breaks test doubles down in xUnit Test Patterns: Refactoring Test Code (p.133):

So there is nothing wrong with using any sort of “test double”, including a stub.

From the Java world where ( up until last year IIRC ) you couldn’t pass lambdas the only solution was to create Mocks.

You have been able to use anonymous classes (a misnomer really, as it’s essentially a classless object) for a long time as ad hoc implementations of interfaces - which is really what you needed as you had to satisfy the entire interface for the sake of static typing.

do we really need mocks at all?

No. You mentioned Detroit-school vs. London-school - Martin Fowler actually uses the terms Classical vs. Mockist Testing. Classical testing existed before mocks emerged and made due with dummies, stubs, and fakes.

But the issue seems to be that you have been operating in the mockist tradition and acquired a distaste for expending effort on implementing dummies, stubs, and fakes.

With regards to the mockist approach even Martin Fowler comments:

2 Likes