4 ms·
Tests are to stop the future programmer from breaking your code.
by erhk 5y ago
Tests are to stop the future programmer from breaking your code.
- postalrat 5y agoBy making tests so brittle you can't change any code without updating tests. And who wants to do that?
- carlmr 5y agoIf the behavior changes, the requirements have changed or you previously had a bug. That's not brittle tests.
- postalrat 5y agoSomeone wants to test: function do_add(a, b, add) { return add(b, a); } And does something like: do_add(1, 2, add) expect(add) to be called with (2, 1) Then the function is changed to: function do_add(a, b, add) { return add(a, b); } Oops, broke the test. Is this a type of behavior change that you expect would break the test? Often there are many ways to correctly do something and a good test should allow any of them.
- carlmr 5y agoBut that's not a behavioral change, only bad testing. The test wouldn't be brittle if the behavior of adding was locked down completely.
- yourenotsmart 5y agoAny test that uses mocks is therefore "bad testing".
- yourenotsmart 5y agoThe very problem is that tests failing is not necessarily due to behavior changing but implementation details not affecting behavior changing. This is especially the case when tests rely on mocks, which don't really implement the BEHAVIOR of a dependency, but rather represent a "replay" of a specific call stack sequence.
- cgrealy 5y agoTests (specifically unit tests) are a way of documenting your assumptions about how a pice of code will be used.
- temporama1 5y agoQED