bazel test Command Reference
Run Bazel test targets with the same caching as builds.
bazel test builds and runs test targets, caching results so unchanged tests are not re-run. It is the test driver for any Bazel-based repo.
What it does
bazel test builds the requested test targets and executes them, caching passing results keyed on inputs. Re-running only re-executes tests whose inputs changed, which keeps large suites fast in CI.
Common flags and usage
- --test_output=errors|all|streamed: how much test output to print
- --test_tag_filters=TAG: include or exclude tests by tag
- --runs_per_test=N: rerun to detect flakes
- --nocache_test_results: force re-running cached tests
- --test_filter=REGEX: run a subset within a target
Example
shell
- name: Test
run: bazel test --config=ci --test_output=errors //...In CI
Pass --test_output=errors so failing tests print their logs instead of just a summary. Cached passing results mean only changed tests re-run, so a PR build tests just what it touched.
Key takeaways
- bazel test caches passing results; only changed tests re-run.
- --test_output=errors prints logs for failing tests in CI.
- --runs_per_test and --test_filter help with flakes and subsets.
Related guides
bazel build Command ReferenceReference for bazel build in CI/CD: build targets and patterns hermetically, scope with target syntax, and ac…
bazel run Command ReferenceReference for bazel run in CI/CD: build then execute a runnable target, pass program arguments after a separa…
bazel query Command ReferenceReference for bazel query in CI/CD: inspect the dependency graph to find reverse deps, scope affected targets…