4 ms·
Even very small "units" have dependencies in the sense of other objects or functions that they use. Or at least they should, if concerns are being separated. It
by sanderjd 3y ago
Even very small "units" have dependencies in the sense of other objects or functions that they use. Or at least they should, if concerns are being separated. It's good to use fakes or mocks to make those dependencies not depend on state external to the test, but not to structure tests around what methods are called on which dependencies in what order.
- RussianCow 3y agoYeah, I guess I would make the distinction between simple stubs and heavyweight mocks and fakes. If you're using a lot of the latter in your unit tests, that's a code smell to me; unit tests should ideally not be concerned with the state of the world, which is where mocks (especially fakes) tend to come in. Obviously there are no absolutes, but that's my rule of thumb and it's served me well.
- sanderjd 3y agoI agree. Mocks tend to be complicated when the api of the dependencies they're mocking is complicated.