About Tests
05 Jun 2024Yesterday, I watched Russ Cox’s video on Go testing titled “Go Testing By Example.” The points and tips provided in the video are very useful for software engineering, regardless of the language you use. I said “software engineering” instead of “programming” because Russ Cox believes there are differences between the two. He thinks software engineering is what happens to programming when you add time and other programmers. That is a good insight and the reason why we should write tests.
Here are the 20 tips from the video. Some of them are specific to Go, but most are applicable to all languages:
- Make it easy to add new test cases.
- Table-Driven Test is your friend
- Use test coverage to find untested code.
- Coverage is no substitute for thought.
- Write exhaustive tests.
- Separate test cases from test logic.
- Look for special cases.
- If you didn’t add a test, you didn’t fix the bug.
- Not everything fits in a table.
- Test cases can be in testdata files.
- Compare against other implementations.
- Make test failures readable.
- If the answer can change, write code to update them.
- Use txtar for multi-file test cases.
- Annotate existing formats to create testing mini-languages.
- Write parsers and printers to simplify tests.
- Code quality is limited by test quality.
- Scripts make good tests.
- Try rsc.io/script for your own script-based test cases.
- Improve your tests over time.
- Aim for continuous deployment.