Testing
Basics
Run all tests: To execute the entire test suite in your local development environment, run
Unit tests for individual go packages: To run tests for individual go packages, like for example
pkg/snet
, invokebazel test
directly and specify the test as a bazel target:bazel test --config=unit //pkg/snet:go_default_test # unit test for exactly pkg/snet bazel test --config=unit //pkg/snet/... # unit tests for all packages under pkg/snet
Run individual go test cases: Use the
--test_filter=<regex>
option to filter on the level of individual test cases.bazel test --config=unit //pkg/snet:go_default_test --test_filter=TestPacketSerializeDecodeLoop
Useful bazel test flags: Finding a flag in the bazel command line reference can be tricky, so here are some pointers:
--nocache_test_results
/-t-
: disable the default caching of test results, to force rerunning them.--test_output=streamed
: show all test output--test_arg=...
: Pass flags to the go testing infrastructure.For example, instead of the
--test_filter=<regex>
mentioned above we could also filter tests with--test_arg=-test.run=<regex>
. This can be used to run benchmarks.