Testing & Code Coverage
Relevant source files
The following files were used as context for generating this wiki page:
Horizon maintains a rigorous quality assurance framework centered around a minimum 90% test coverage requirement. The testing infrastructure is designed to support a multi-crate Rust workspace, ensuring that every function includes unit tests and that edge cases—such as empty inputs and boundary conditions—are thoroughly validated.
Sources: AGENTS.md:144-147, AGENTS.md:183, codecov.yml:21
Testing Infrastructure
The project utilizes a standard Rust testing stack supplemented by specialized crates for property-based testing, mocking, and logging. Tests are primarily organized as #[cfg(test)] modules within the same file as the source code they validate.
Core Testing Dependencies
The workspace defines a comprehensive suite of testing utilities in the root configuration:
| Crate | Purpose |
|---|---|
rstest | Fixture-based testing and parameterized tests |
proptest | Property-based testing |
fake | Generation of fake data for testing |
wiremock | HTTP mocking for API integration tests |
test-log | Logging support during test execution |
Sources: Cargo.toml:104-111, AGENTS.md:148-150
Test Execution Commands
Developers and AI agents are required to use specific commands to ensure consistency:
# Run all tests in the workspace
cargo test --all-features
# Test a specific crate
cargo test -p error
# Run a specific test module
cargo test -p error::lib::tests --lib
# Run tests with console output
cargo test -p cli -- --nocapture
Sources: AGENTS.md:27-36
Code Coverage System
Horizon uses grcov for coverage instrumentation and Codecov for reporting and quality gates. The coverage system specifically excludes the UI crate (src-tauri) and internal cargo directories to focus on backend business logic and security-critical components.
Coverage Workflow
The following diagram illustrates the data flow from test execution to report generation.
The workflow ensures that instrumentation occurs during test execution, resulting in raw profile data processed into multiple formats.
Sources: scripts/run_coverage.sh:14-53, codecov.yml:21-25
Coverage Scripts and Configuration
The project includes a dedicated shell script to automate the coverage generation process. It utilizes RUSTFLAGS="-Cinstrument-coverage" to prepare the binary for profiling.
# Generate HTML and LCOV reports
./scripts/run_coverage.sh
The reports are stored in target/coverage/html/index.html.
Sources: scripts/run_coverage.sh:18-35, AGENTS.md:183-185
Quality Gates
Coverage requirements are enforced via codecov.yml:
- Target: 90% overall project coverage.
- Threshold: 1% (allowable drop before failure).
- Requirement: CI must pass before merging.
- Precision: 2 decimal places.
Sources: codecov.yml:1-25
Testing Levels and Strategy
The implementation plan defines a multi-tiered testing strategy ranging from unit tests to end-to-end (E2E) validation.
Testing Tiers
- Unit Testing: Target of 80-90% coverage for core business logic, utilizing
rstestfor fixtures and data generators. - API Integration Testing: Testing of CRUD endpoints, error handling, and authentication flows using test database fixtures.
- End-to-End (E2E) Testing: Utilizing Playwright to test critical user workflows and authentication paths.
- Security Testing: Inclusion of OWASP ZAP for vulnerability scanning and rate-limiting tests.
Sources: IMPLEMENTATION_PLAN.md:465-492, AGENTS.md:183
Specialized Testing: Error Handling
The error crate contains extensive unit tests for its response and code structures. For example, tests ensure that ApiResponse correctly maps data, handles pagination offsets, and serializes to the correct JSON format.
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_not_found_new() {
let err = NotFound::new("User");
assert_eq!(err.code(), "NOT_FOUND");
assert_eq!(format!("{}", err), "User not found");
}
}
Sources: crates/error/src/codes.rs:370-380, crates/error/src/response.rs:310-330
Implementation Roadmap (Testing)
The roadmap specifies the sequential setup of testing infrastructure during the "Testing and Hardening" phase.
| Phase ID | Deliverable | Description |
|---|---|---|
| R-01 | Unit Testing Infrastructure | Setup of rstest, fixtures, and data generators. |
| R-02 | API Integration Testing | Implementation of authentication and CRUD endpoint tests. |
| R-03 | End-to-End Testing | Setup of Playwright for critical workflow validation. |
| R-04 | Security Testing | Integration of OWASP ZAP and rate-limiting audits. |
Sources: IMPLEMENTATION_PLAN.md:465-492
Testing and code coverage are integral to the Horizon development lifecycle. By enforcing a 90% coverage mandate through automated scripts and strict Codecov configurations, the project ensures that infrastructure management remains reliable and secure.