Skip to content
Latchkey

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

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →