liveBook · Manning

Code coverage

As explained in Effective Platform Engineering

Test coverage is the proportion of specified code, paths, branches, or behaviors exercised by automated tests.

Code coverage measures the proportion of specified code, paths, branches, or behaviors exercised by automated tests. It acts as an early signal of code quality rather than a complete measure of software reliability. section 10.1.2 section 10.8

Coverage can guide improvement before production problems occur, especially when combined with code-quality violations and the ratio of manual to automated tests. It should therefore inform engineering decisions alongside delivery and reliability measures. section 10.1.2

Blocking deployments below 80% coverage

An engineering organization requires custom code to reach 80% coverage. A Kubernetes admission controller sends deployment metadata, including a commit SHA, to an OPA policy. The policy retrieves matching coverage results from Codacy, compares the reported value with 80, and denies deployment when the value is lower. A result for commit bc183a62 reports 98% coverage, so it satisfies the threshold. section 4.2.1

package test

# http.send request passing our input data could go here

default deny := false

deny if code_coverage_lt_required

code_coverage_lt_required if {
 data.code_quality_attributes[input.request.object.metadata.sha].coverage < 80
}

Inspect the Rego rule that retrieves code-quality data and denies deployment when coverage falls below the required threshold. section 4.2.1

A practical coverage gate requires:

  • A reporting system that records coverage against an identifiable commit or deployment revision. section 4.2.1
  • A policy that defines the required threshold and specifies the response when coverage data is below it. section 4.2.1
  • Complementary metrics that connect coverage to developer productivity, operational efficiency, and customer outcomes. section 10.1.2

How Effective Platform Engineering covers it

How deep it goes
Defines an 80% threshold and traces result retrieval, comparison, and deployment denial through an OPA admission policy.
Examples
Uses Codacy results keyed by commit SHA, an AdmissionReview payload, and an OPA rule denying coverage below 80%.
What you can do after
Operate/configure OPA admission control to compare reported coverage with a required threshold before deployment.
How it connects
Connects coverage to automated tests, code quality, deployment pipelines, Kubernetes admission controllers, and policy-as-code.

Also explained in

Compare how 14 books explain code coverage →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Effective Platform Engineering. The section links point to the parts of the book it draws on.