How to Test¶
Run all tests¶
bazel test //...
Run a specific target:
bazel test //path/to:target
Force re-execution (skip cache):
bazel test //... --nocache_test_results
Write a C++ test¶
GoogleTest is integrated via Bazel. Define test targets using cc_test:
cc_test(
name = "my_test",
srcs = ["my_test.cc"],
deps = [
"//src:my_library",
"@googletest//:gtest_main",
],
)
Write a Rust test¶
Native Rust tests work through rules_rust. Define test targets using the standard Rust test model.
Write a Python test¶
pytest-based tests are integrated through Bazel's Python rules.
Use the Integration Test Framework (ITF)¶
ITF is a pytest-based framework for target-oriented testing:
- Use the
py_itf_testBazel macro to define test targets - Plugin model supports Docker, QEMU, and hardware targets
- Declare required capabilities using the
@requires_capabilitiesdecorator
See the ITF project documentation for detailed usage.
Collect coverage¶
bazel coverage //... --combined_report
- C++: Compiler instrumentation via bazel_cpp_toolchains
- Rust: LLVM-based source coverage
Enable sanitizers¶
score_cpp_policies provides selectable sanitizer features:
| Sanitizer | Purpose |
|---|---|
| ASan | Address errors (buffer overflow, use-after-free) |
| UBSan | Undefined behavior |
| LSan | Memory leaks |
| TSan | Data races |
Enable sanitizers via Bazel select() expressions in your build configuration.