4 ms·
How are mocks a smell if "unit testable with (possibly fake) dependencies" is okay? That's what mocks are. Or do you mean specifically "expecting" interactions
by delecti 4y ago
How are mocks a smell if "unit testable with (possibly fake) dependencies" is okay? That's what mocks are.
Or do you mean specifically "expecting" interactions with those mocks? Because I agree that's usually not that valuable.
- Cyph0n 4y agoFakes are not mocks. A fake is an actual implementation of the dependency that runs in-process/in-memory. This means that, unlike with mocks, your test code does not dictate the behavior/outputs of the dependency. Ideally, service/library owners would write and maintain the fake to ensure that it stays in sync as changes are made to the actual service.
- sanderjd 4y agoBasically what Cyph0n said, fakes and mocks aren't the same thing. But it isn't quite as smelly when I see a mock (or "stub" more typically) used as an expedient way to create a fake to pass in as a dependency. Like you said, it is asserting on the interactions with a mock that is what primarily smells bad to me. I very rarely (honestly I think maybe never) see this done in a way that isn't just rewriting the implementation of the method as expectations in the test.