Advanced Testing Topics
#Advanced Testing with Go
Advanced Testing with Go by Michelle Hashimoto - video, slides,
code
Notes:
Testing with golden files and updating them (go test -update to save in testdata).
// - advanced/advanced-testing/golden_test.go -
Having testing.go or testing_.go (or file_testing.go) to provide Testing API.
// - advanced/advanced-testing/testing.go -
network_testing.go server listner fixture (see https://github.com/hashicorp/go-plugin ).
// - advanced/advanced-testing/network_testing.go -
subprocessing_test.go testing subprocesses with Entrypoint
// - advanced/advanced-testing/subprocessing_test.go -
#Testing Techniques
Testing Techniques by by Andrew Gerrand: video slides
#Go Testing By Example
Go Testing By Example by Russ Cox
- Make it easy to add new test cases.
- 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.
#Testing Patterns
A test is not a unit test if:
- It talks to the database
- It communicates across the network
- It touches the file system
- It can’t run at the same time as any of your other unit tests
- You have to do special things to your environment to run it.