Re:Stop mocking your system
by wccrawford on Sunday July 04, 2021 @06:31PM
(#27733153)
This sounds exactly right to me. You write mocks for the things that could take too much time to run frequently with the real code. (And I'm assuming you'd also write it for things that you don't want to make actual changes somewhere, such as a third-party API that you don't control.)
But if it could be run locally, quickly, you wouldn't bother mocking it.
If that's all correct, I think you and I would do the same things. All the people screaming "no mocks!" and "mock everything!" are scary, IMO.
Yeah, he's talking to you for sure.
Yep, and he did a very bad job at it (and so do you) if the goal was to change my mind. Do you maybe have arguments?
Re:Stop mocking your system
by shadowlight on Sunday July 04, 2021 @07:35PM
(#27733477)
Mocks mean your code is too tightly coupled. You should be able to unit test your code by creating only fake data.
Things like dependency injection increase coupling to the point where you have to mock. Avoid dependency injection and other complexity within complexity features.
Having a set of very fast running tests is absolutely necessary in my opinion.
Once I have validated that the piece of code I wrote is doing what I intended, then I want to run other tests that do not use mocks/fakes, e2e tests that can possibly take a whole day to complete and will allow me to see if the whole system still works fine with my new feature plugged in. But this comes AFTER fast unit tests, and definitely cannot REPLACE those.