2 ms·
I use the following list to decide on creating a unit test or not. More yeses means a unit test is a good idea. 1. Is it hard to instantly test the code when i
by koonsolo 10y ago
I use the following list to decide on creating a unit test or not. More yeses means a unit test is a good idea.
1. Is it hard to instantly test the code when implementing it? (Might be the case for library code)
2. Is there a chance the underlying implementation might change (and so might break in the future)?
3. Will the interface of the class remain stable? (If not unit test needs to be rewritten too)
4. Will functional tests pass when something breaks in this class?
- alkonaut 10y agoI often try to write a unit test just to see whether it's possible. If not (i.e. one of the questions was no) there is always a chance that the design can be improved. E.g. can the interface be minimized to something that is stable, and simpler to test? Testable code tends to be better (have less dependencies, less state etc) than non testable code. So making it testable is a goal in itself, even if the tests are never even committed.