Have you ever had the experience of feeling utterly surprised by a question? I mean that someone asks you a question that causes you to scream an “obvious” answer inside your head. The answer seems so obvious in fact that you wonder why someone would ever ask the question in the first place.
I’ll try not to read too much into that
Anyways, thanks for choosing to elaborate on the topic in a full post. I think it will benefit a lot of readers (me included), and I’m glad I stumbled across it.
I am confused about your perspective on something after reading this post though, and wanted to ask for some clarification. Maybe there is another hidden assumption you can uncover :).
The context of my question is this. Your post begins by discussing two implementations of a Repository. One is the production MySQL implementation, and the other a lightweight in-memory implementation. The in-memory implementation is beneficial testing, and because it is a hand-written, static implementation, it allows it to participate in Contract tests (perhaps this is a wrong assumption, and dynamic mocks/test doubles can too?). Being able to Contract test your test implementation is beneficial to increase your confidence that it acts like the real thing. I like that.
But then you say:
…when I write tests and need test doubles, I tend to write them using a test double library (JMock, NSubstitute, rspec-mock…), even when writing them “by hand” is objectively easier.
And further on:
So it goes with me and test doubles in Collaboration Tests. I like consistency and I feel comfortable with dynamic test doubles, so I use them even in situations in which a simpler alternative would work equally well.
Firstly, when you say dynamic test doubles, do you mean syntax like Mockito’s when(myRepo.findAllUsers()).thenReturn(foo)
? If so, don’t these little mocks you setup preclude you from the benefits of Contract tests? For example, how can you be sure these little mock implementations behave like the real thing?
And secondly, I am also wondering what you mean by a simpler alternative. Maybe an example would help clarify here.
I hope my questions were clear. I know it takes a lot of energy sometimes to try to understand where someone is coming from. Thanks in advance.