4 ms·
Unit tests are "correct" by definition, because they represent the specification for the code that they test. You aim to encapsulate all the intended behaviour
by auxbuss 16y ago
Unit tests are "correct" by definition, because they represent the specification for the code that they test.
You aim to encapsulate all the intended behaviour in your tests.
Thus, when you encounter a bug, you start by creating a test that replicates the bug, correct the test to the expected behaviour (so it now fails), then fix the code. That is: red, green, refactor.
Not only do you fix the bug, but you improve the specification and improve the efficacy of your tests.
In the way that you cannot pragmatically prove that code has no bugs, neither can you prove your tests are correct (bug-free). But by having a test suite that can run continuously, and that you add to, you are increasingly improving code quality and, most importantly, ensuring that regressions don't occur.
- silentbicycle 16y ago> Unit tests are "correct" by definition, because they represent the specification for the code that they test. No, those are acceptance tests. (It's really too bad they can't be the code. Talk about DRY!) Besides, how does one write tests for bugs they don't know about? (Or can they only be written after the fact?) Wouldn't it be helpful to have some sort of declarative specification so that the compiler itself can generate exhaustive tests?