3 ms·
IMO/IME, mocks in unit tests can be extremely dangerous when used alone, in non-static-typed languages. Changes in interfaces or behaviour of a module won't br
by whstl 3y ago
IMO/IME, mocks in unit tests can be extremely dangerous when used alone, in non-static-typed languages.
Changes in interfaces or behaviour of a module won't break the unit tests of modules that depend on it. So you must rely on either typechecking (not available in all languages) or integration tests (which will then trigger a change that will cause the unit-test-with-mocks to break).
If there is neither to help, you code just breaks in production.
Not only that, but this can cause some design ossification: classes that have too many dependents become very difficult to change, since you now also have to modify all mocks of it.
- bvrmn 3y agoIn Python one could use auto specs to be sure test would be broken on calling mocks with changed API[1]. I don't think it's hard to implement (if already not) similar feature for other dynamic languages. [1]: https://docs.python.org/3/library/unittest.mock.html#auto-speccing https://docs.python.org/3/library/unittest.mock.html#auto-sp...