Python Approval Testing — ELI5
Imagine you bake a cake and it comes out perfect. You take a photo of it. Next time you bake, you compare your new cake to the photo. If it looks the same, great. If something looks different — frosting is lopsided, layers are uneven — you decide whether the change is okay or a mistake.
Approval testing works the same way with code output. Instead of writing rules like “the report should have 15 rows and column A should be numbers,” you run the code once, check the output with your own eyes, and save it as the “approved” version.
Every time tests run after that, the code’s output is compared to the approved version. If they match, the test passes. If they differ, the test fails and shows you exactly what changed. You then decide: was this change intentional (approve the new version) or a bug (fix the code)?
This is especially handy when the output is complicated — like a long report, a formatted email, or a chunk of data. Writing individual checks for every piece of that output would be exhausting. Approval testing lets you verify the whole thing at once.
The tradeoff is that you need a human to look at the output initially and say “yes, this is correct.” But once approved, the computer handles all future comparisons automatically.
One thing to remember: Approval testing flips the script — instead of describing what correct output looks like, you show an example and say “like this.”
See Also
- Python Acceptance Testing Patterns How Python teams verify software does what real users actually asked for.
- Python Behavior Driven Development Get an intuitive feel for Behavior Driven Development so Python behavior stops feeling unpredictable.
- Python Browser Automation Testing How Python can control a web browser like a robot to test websites automatically.
- Python Chaos Testing Applications Why breaking your own Python systems on purpose makes them stronger.
- Python Contract Testing Why contract testing is like having a written agreement between two teams so neither one accidentally breaks the other's work.