Write code to set the class in the right state. Check immediately.
By convention, the number of errors flagged in a test is returned as an exit status, i.e., if one thing goes wrong, we return 1
.
There’s lots of repetitive code to create test drivers:
- Set up the test.
- Check if the test passed.
- Run all the tests.
- Output appropriate messages.
- Collect statistics.
This can get tedious, so there are many unit test frameworks to simplify building unit tests, like UnitTest++ (for C++).
Addendums
This code will never ship to the end-user. So we should have tests within a separate sub-directory.