Running Tests
Run All Tests
Execute the entire test suite:Run Specific Test Targets
Test Organization
Tests are organized in thesrc/test/ directory tree, mirroring the structure of the source code:
Test infrastructure that is complex enough to warrant its own tests, or is used by multiple packages, goes into a
testing subpackage in src/main/ with targets marked as testonly.Integration Tests
Integration tests verify that multiple components work together correctly. They are located in:src/test/kotlin/org/wfanet/measurement/integration/k8s/- Kubernetes integration testssrc/test/kotlin/org/wfanet/measurement/integration/common/- Common integration utilities
Running Integration Tests
Correctness Tests
Correctness tests validate the accuracy of measurement computations against expected results. These tests typically run against a full CMMS deployment.Synthetic Generator Correctness Test
This test validates end-to-end measurement accuracy:Test Configuration with Make Variables
Many integration and correctness tests require configuration via Bazel’s--define flag:
TestContainers
Some tests use TestContainers to spin up Docker containers for dependencies like databases.Testing Best Practices
Unit Testing Standards
Test the Contract
Test public APIs, not implementation details. Internal functionality should not be exposed just for testing.
Use Test Doubles Wisely
Choose appropriate test doubles:
- Fakes for working implementations
- Mocks for behavior verification
- Stubs for simple responses
- Real dependencies when practical
Smaller Test Cases
Bias toward more, smaller test cases rather than fewer large ones.
Truth Assertions
Use the Truth library for Kotlin test assertions, including ProtoTruth for protocol buffers.
Writing Tests in Kotlin
CI/CD Testing
Continuous integration runs tests automatically on pull requests and commits. The CI pipeline:- Runs formatters and linters
- Executes all unit tests
- Runs integration tests where applicable
- Checks for compiler warnings
- Validates code coverage
All tests must pass before a pull request can be merged. See the Contributing Guide for more information.
Test Output Options
Monitoring Test Execution
For correctness tests running against a deployed system, you can monitor progress through:- Pod logs in Kubernetes clusters
- Spanner database queries to check measurement states
- Test output with
--test_output=streamed
Next Steps
Dev Standards
Learn about code review and commit standards
Contributing
How to contribute to the project