Expand description
Code coverage integration for fastapi_rust.
This module provides coverage tracking and reporting infrastructure for
testing fastapi applications. It integrates with cargo-llvm-cov for
line-level coverage and provides per-endpoint coverage tracking.
§Features
- Endpoint coverage tracking: Track which routes are tested
- Branch coverage hints: Track error paths and edge cases
- Threshold enforcement: Fail tests if coverage drops below threshold
- Report generation: JSON, HTML, and badge formats
§Example
ⓘ
use fastapi_core::coverage::{CoverageTracker, CoverageConfig};
// Create a coverage tracker
let tracker = CoverageTracker::new();
// Run tests with tracking
let client = TestClient::new(app).with_coverage(&tracker);
client.get("/users").send();
client.post("/users").json(&user).send();
// Generate report
let report = tracker.report();
report.assert_threshold(0.80); // Fail if < 80% coverage
report.write_json("coverage.json")?;
report.write_html("coverage.html")?;§CI Integration
Use with cargo-llvm-cov for full line-level coverage:
# Install coverage tools
cargo install cargo-llvm-cov
# Run with coverage
cargo llvm-cov --html --open
# CI: Check threshold
cargo llvm-cov --fail-under-lines 80Structs§
- Branch
Hits - Branch coverage for specific code paths.
- Coverage
Config - Configuration for coverage tracking.
- Coverage
Report - Coverage report with statistics and utilities.
- Coverage
Tracker - Tracks endpoint coverage during test execution.
- Endpoint
Hits - Endpoint hit statistics.
Enums§
- Output
Format - Output format for coverage reports.