Automated Testing Gates
16 min
Now that pipelines established stage ORDER, this module covers what
decides whether a stage actually PASSES. An automated testing gate
checks measurable thresholds — test pass rate, code coverage — and
blocks the pipeline from proceeding to deployment if either one falls
short. The value isn't just catching bugs; it's that the check is
automatic and consistent, immune to "we're behind schedule, let's just
ship it" pressure that could compromise a manual review.
def deployment_gate(pass_rate, coverage, min_pass_rate=0.95, min_coverage=0.80):
if pass_rate < min_pass_rate:
return "blocked: pass rate too low"
if coverage < min_coverage:
return "blocked: coverage too low"
return "approved"
Pass rate is checked BEFORE coverage on purpose -- a failing test is a more urgent signal than insufficient coverage (something is provably broken vs. something might be untested), so the gate reports whichever problem is more actionable first rather than listing every issue at once.
Write `deployment_gate(pass_rate, coverage, min_pass_rate=0.95, min_coverage=0.80)`: return `'blocked: pass rate too low'` if `pass_rate < min_pass_rate`; else `'blocked: coverage too low'` if `coverage < min_coverage`; else `'approved'`.
Why does a real CI/CD pipeline enforce a testing gate automatically, rather than just letting a human decide whether to deploy after looking at the test results?
You can implement an automated deployment gate that enforces test-quality thresholds consistently, without relying on manual judgment under pressure.