3 ms·
Writing tests is indeed a great opportunity for finding bugs. But a codebase with good test coverage allows you to safely perform large scale refactorings with
by ithkuil 3y ago
Writing tests is indeed a great opportunity for finding bugs.
But a codebase with good test coverage allows you to safely perform large scale refactorings without having regressions and that's useful property even if you have bugs and the refactoring preserves them faithfully.
The risk of using a tool that generates tests designed to encode the current behaviour is that you may be lulled in a false sense of safety, while all you've done is to encode the current behaviour, as advertised.
Perhaps this problem can be just solved by not calling these tests "tests" but something like "behavioural snapshots" or something like that (cannot think of a better name, but the idea is to capture the idea that they were not meant to encode necessarily the correct behaviour but just the current behaviour)
- drothlis 3y agohttps://en.wikipedia.org/wiki/Characterization_test https://en.wikipedia.org/wiki/Characterization_test aka snapshot tests.
- ithkuil 3y agoI'm a huge fan. But sometimes it's hard to produce the snapshots.
- the_gipsy 3y agoSometimes you could replace snapshots with checksums. In other words, they're just alerts that code changed, or make changing code unnecessarily tedious.
- ape_key 3y agoUnit tests are dead weight during refactoring. Integration tests are useful. Code coverage metrics are most easily met by writing unit tests. Unit tests are tedious to write. If you have a robot writing unit tests, I do not want to see your codebase. Refactor all day long. I’m not going near it.
- TillE 3y agoIt is not at all uncommon for me to refactor the internals of a unit (ie, a class) in order to add a feature. Unit tests are extremely useful here.
- nitwit005 3y agoMeta is specifically writing unit tests, where probably every part of the system except the code being tested is mocked. Those tests tend to have very low value with testing significant refactoring, as the code the tests covers often won't exist anymore.