Skip to main content

Module coverage

Module coverage 

Source
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 80

Structs§

BranchHits
Branch coverage for specific code paths.
CoverageConfig
Configuration for coverage tracking.
CoverageReport
Coverage report with statistics and utilities.
CoverageTracker
Tracks endpoint coverage during test execution.
EndpointHits
Endpoint hit statistics.

Enums§

OutputFormat
Output format for coverage reports.