Testing Overview
The testing infrastructure spans multiple directories and frameworks:- Unit tests - Co-located with source code in
rs/subdirectories - Integration tests - In
rs/tests/directory - System tests - End-to-end tests using the test driver framework
- PocketIC tests - Canister testing using lightweight IC instances
- Property tests - Randomized testing using proptest
Test Organization
Unit Tests
Unit tests are co-located with the code they test, following Rust conventions:Integration Tests
Integration tests live in thers/tests/ directory, organized by feature:
System Tests
System tests validate the entire IC stack in a realistic environment.Test Driver Framework
The system test driver executes setup and test functions in Rust, managing virtual machines through the Farm backend service:Running System Tests
Inside Dev Container
With Pre-built Artifacts
Test Environment
A test environment is a directory structure containing:- Infrastructure configuration (Farm URL, etc.)
- Topology data for deployed Internet Computer instances
- Test artifacts and logs
Working Directory Structure
PocketIC Testing
PocketIC provides lightweight, fast canister testing without requiring full IC infrastructure.Overview
PocketIC is a local canister testing solution that works with the PocketIC server to provide deterministic, fast test execution.Fast Execution
Tests run in milliseconds, not seconds
Deterministic
Reproducible test results
Rust Native
First-class Rust API
Multi-Subnet
Test cross-subnet calls
Quick Start
Download PocketIC Server
Download the PocketIC server binary compatible with your library version.
Example Test
Use Cases
- Canister logic testing - Unit test individual canister functions
- Multi-canister scenarios - Test inter-canister calls
- Upgrade testing - Test canister upgrade logic
- State management - Verify state persistence and stability
Consensus Test Framework
The consensus test framework provides specialized testing for consensus-related functionality.Framework Components
Located inrs/consensus/tests/framework/, the framework includes:
- Mock consensus components
- Test utilities for DKG and threshold signatures
- Integration test helpers
Consensus Integration Tests
Consensus integration tests validate:- Block production and validation
- Finalization behavior
- Notarization processes
- DKG and IDKG protocols
- Chain key operations
Property-Based Testing
Property-based tests use the proptest framework to generate randomized test inputs:*proptests.rs throughout the codebase.
Running Tests
Local Testing
- Cargo
- Bazel
Code Linting
Before running tests, verify code quality:Coverage
Generate code coverage reports:Test Best Practices
Reproducibility
Reproducibility
- Use fixed RNG seeds or log random seeds
- Avoid dependencies on system time or external state
- Make tests deterministic and isolated
Logging
Logging
- Use test environment logging primitives, not
println! - Add ASCIIDOC descriptions at the beginning of test files
- Log relevant test parameters for debugging
Organization
Organization
- Place tests in appropriate subdirectories
- Update CODEOWNERS when adding new test directories
- Keep test names descriptive and consistent
Performance
Performance
- Keep unit tests fast (< 1 second)
- Use PocketIC for canister tests instead of full system tests
- Tag slow tests appropriately for CI filtering
Testing in CI/CD
For external contributors:Before Submitting PR
Specialized Test Types
Fuzz Testing
Fuzz tests are located inrs/fuzzers/ and use cargo-fuzz:
Determinism Tests
Validate deterministic execution inrs/determinism_test/.
Universal VM Tests
System tests can run Docker containers in Universal VMs. Search forUniversalVm::new in the codebase for examples.
Universal VMs are created fresh for each test suite, requiring container images to be fetched each time.
Related Resources
Workspace Structure
Understand the monorepo organization
Contributing
Guidelines for contributing code and tests
PocketIC Documentation
Full API documentation for PocketIC
Testing Terminology
Comprehensive testing terminology guide