Testing¶
Running Tests¶
bazel test //...
Run a specific target:
bazel test //path/to:target
Force re-execution (skip cache):
bazel test //... --nocache_test_results
C++ Tests¶
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",
],
)
Rust Tests¶
Native Rust tests work through rules_rust. Define test targets using the standard Rust test model.
Python Tests¶
pytest-based tests are integrated through Bazel's Python rules.
ITF Integration Testing¶
The Integration Test Framework (ITF) is a pytest-based framework for target-oriented testing. Key characteristics:
- Uses the
py_itf_testBazel macro to define test targets - Plugin model supports Docker, QEMU, and hardware targets
- Tests declare required capabilities using the
@requires_capabilitiesdecorator
See the ITF project documentation for detailed usage.
Coverage¶
Collect LCOV coverage data:
bazel coverage //... --combined_report
- C++: Compiler instrumentation via bazel_cpp_toolchains
- Rust: LLVM-based source coverage
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.