Testing Framework & Continuous Execution · 40 min · pytest · Hypothesis · mutmut
The Verification Pyramid for AI Code
Unit every commit. Property every commit. Mutation nightly. Security every PR. Formal at release.
Real-world application: Engineers who can design a verification pyramid for AI code demonstrate testing architecture expertise.
What you will learn
- Design the verification pyramid for AI code with 6 layers
- Determine what to run when: commit, PR, nightly, release
- Apply cost vs confidence tradeoffs for each verification layer
- Map all tools from Phases 1-7 to pyramid layers
Introduction
The Verification Pyramid for AI Code
Objective
Run the verification pyramid simulator. Observe the 6-layer pyramid, execution schedule (commit, PR, nightly, release), cost-confidence analysis for 3 strategies (Full Pyramid, Unit Only, All on Every Commit), and the 'what to run when' guide. Compare cost-effectiveness of each strategy.
Unit every commit. Property every commit. Mutation nightly. Security every PR. Formal at release.
The Problem
You have 13+ quality gates from Phases 1-7. Running all of them on every commit is too slow and too expensive. This lesson covers the verification pyramid -- a layered model that determines what to run when, balancing cost and confidence.
The 6-layer verification pyramid
┌───────────┐
│ Formal │ Release only
│ (Z3) │ Highest confidence, highest cost
└───────────┘
┌─────────────────┐
│ Security │ Every PR
│ (SAST+SCA+AI) │ High confidence, medium cost
└─────────────────┘
┌───────────────────────┐
│ Integration │ Every PR
│ (End-to-end tests) │ Medium confidence, medium cost
└───────────────────────┘
┌───────────────────────────────┐
│ Mutation Testing │ Nightly
│ (mutmut) │ High confidence, high cost
└───────────────────────────────┘
┌───────────────────────────────────────┐
│ Property-Based Testing │ Every commit
│ (Hypothesis) │ Medium confidence, low cost
└───────────────────────────────────────┘
┌───────────────────────────────────────────────┐
│ Unit Tests │ Every commit
│ (pytest) │ Low confidence, low cost
└───────────────────────────────────────────────┘
Layer details
| Layer | Tool | When | Cost | Confidence | Duration |
|---|
| Unit Tests | pytest | Every commit | Low | Low | 35s |
| Property-Based | Hypothesis | Every commit | Low | Medium | 130s |
| Mutation | mutmut | Nightly | High | High | 300s |
| Integration | pytest + requests | Every PR | Medium | Medium | 120s |
| Security | Bandit+Semgrep+SCA+AI | Every PR | Medium | High | 60s |
| Formal | Z3 SMT | Release only | Very High | Very High | 600s |
The cost-confidence tradeoff
Each layer trades cost for confidence. Unit tests are cheap (35s, free) but have low confidence (they only test what you thought to test). Formal verification is expensive (600s, requires Z3 expertise) but has very high confidence (mathematically proven). The pyramid runs cheap, low-confidence layers frequently (every commit) and expensive, high-confidence layers rarely (release only). This maximizes confidence per dollar spent.
Why does mutation testing run nightly instead of on every commit?
Mutation testing runs nightly instead of on every commit for 4 reasons: (1) Cost: Mutation testing takes 300s (5 minutes) even with caching. Without caching, it takes 10+ minutes. If you run it on every commit (say 20 commits/day for an active team), that's 100-200 minutes of CI time per day just for mutation testing. Nightly runs take 5-10 minutes once per day. This saves 95% of the CI cost. (2) Value: Mutation testing measures test quality, not code quality. It answers the question 'Do my tests actually catch bugs?' This doesn't change much between individual commits -- if your tests were good yesterday, they're probably still good today. What matters is the trend over time: is your mutation score improving or degrading? Nightly runs capture this trend without the noise of per-commit fluctuations. (3) Feedback: Mutation testing results are not actionable per-commit. If your mutation score drops from 88% to 85% on a single commit, you can't 'fix' it in that commit -- you need to write more tests, which is a separate effort. Per-commit mutation results would just be noise. Nightly results give you a trend that you can act on: 'Our mutation score has dropped 5% this week -- we need to invest in test quality.' (4) CI resources: Nightly runs use off-peak CI capacity. During the day, CI runners are busy with per-commit gates (unit tests, PBT, linting, type checking). Running mutation testing at night doesn't compete with developer feedback for CI resources. However, there's an exception: mutation testing SHOULD run on PRs that significantly change test files. If a PR adds new tests or modifies existing tests, running mutation testing on that PR verifies that the new tests actually catch bugs. This can be configured with path filters: only run mutation testing when src/tests/ files are changed."
This lesson is free
You've read the first 3 sections. The rest covers The Concept, Build, Check Yourself, Key Terms & Next. A free account opens all of it, with its practice questions and its lab. No card.
Create a free account — the opening phases of 29 of 35 courses, and the first lesson of every phase, are free, no credit card.
Browse all courses · View pricing · DeVenture Academy