Master AI Agent Engineering
I recently released my AI Agent Engineer video course on agentic engineering: 10 modules, 55 video lessons, 27 hands-on tasks, and 3.5 hours of video.
You learn harness engineering, testing best practices for AI-written code, and how to build your own AI assistant that works 24/7.
Last 24 hours to save $75.
Click here to get instant access →
Motivation
Both AI and developers are terrible at writing tests.
I see the same mistake in every team I work with: developers use the same Claude session to write both the code and the tests, and their tests are based on the same wrong assumptions as the code.
Another issue is that your agent’s tests pass because the agent wrote them to pass. They cheat often.
And a green test suite tells you one fact: the inputs someone picked did not fail.
But the nasty bugs don’t lie in the happy paths.
They lie in the edge and corner cases.
Unit, integration and e2e tests are not enough.
You need tools that search for the failing input: property-based testing finds it by chance, and formal verification finds it by proof.
Anthropic showed that AI models are now good enough to write these proofs on their own, and Opus 5.5 writes them faster than any model before it. Claude used proofs on 123 open-source libraries and found hundreds of bugs that years of random testing had missed.
In this article, I will teach you the methods Anthropic uses, from property tests to formal verification, and how to use them in your projects. At the end, I give you free skills for your coding agent, so you can start using these methods right away.
The 5 Levels of Verification
I sort every way to test code into five levels:
1. Example tests: you pick the inputs. These are the good old unit, integration and e2e tests every developer has been writing for decades. A passing test means the code works for those inputs only.
2. Property tests: the tool picks a big number of random inputs and runs the test on each of them. A passing test means the code works for the random inputs it tried.
3. Bounded checking: the tool searches all inputs, with loops up to N iterations. A passing check means no input breaks the rule within that bound.
4. Full proof: the tool proves the rule for all inputs. A passing proof means no input breaks the rule, with no limit.
5. Design checking: the tool searches every order of steps in a design. A passing check means no order of steps breaks the rule.
Levels 1 and 2 are testing, and levels 3 to 5 are formal verification. Levels 1 to 4 check your code against more and more inputs. Level 5 checks every order of steps in a design.
Let’s take one simple function and test it at each level. The function refunds a payment, in cents, minus a fee of 3%, at least 30 cents:
It looks correct and passes a code review. But there is an edge case: a payment under 30 cents, like a 20-cent tip, makes the fee bigger than the payment, and paid - fee throws an error on a u64.
Let’s see how each type of test can catch this bug.
1. Example Tests
Unit, integration and e2e tests share one mechanism: you write the input and the expected output.
Every example test depends on the inputs that you or your agent pick. This test uses 10,000 cents, so it passes. It leads to 100% code coverage in the refund function, and it still misses the bug.
When nobody picks an edge case, like a payment under 30 cents, the suite stays green and you ship a bug.
Example tests are cheap, fast and readable, so keep them.
⚠️ Be careful with the false sense of security that AI-written tests give you. Coding models are trained to make the test suite pass, so they often write tests that the code already passes. A good test searches for the input that breaks the code.
2. Property Tests
A property test replaces the example with a rule: a fact that must be true for every input, like “a refund is never more than the payment”. Developers call such a rule an invariant. Every level from here on checks a rule like this one. You state the rule and set the input range. Then the tool generates random inputs in that range.
In this test, the proptest library generates 256 random numbers in the range of 0 to 1,000 and runs the test for each one. When an input fails, proptest shrinks it to the smallest failing case: paid = 0.
I ran this test 20 times for each input range:
0..1_000: it found the bug in 20 of 20 runs.Full
u64range (paid: u64): 0 of 20 runs.
A property test finds this bug only when the generator produces a value under 30, so the input range you set decides whether the test finds it.
💡 When you create property-based tests, generate small values and boundary values (0, 1, MAX) on purpose.
Use Property Testing for: parsers, encoders, money math and sorting. For UI and CRUD forms, example tests and property tests are enough.
👉 To learn property-based testing in depth, read my article How I write 1000s tests with little effort.
3. Bounded Checking (Kani)
Bounded checking checks the same kind of rule as a property test, but on every input, up to a size limit such as the length of a list. It is the first level of formal verification: if no input breaks the rule, the tool gives you a proof that your code works within that limit.
Kani is that tool for Rust, built by AWS. A Kani harness looks like a unit test with one change: kani::any() stands for every possible value.
cargo kani fails in 0.3 seconds, on every run, and points at paid - fee: attempt to subtract with overflow.
Kani does not run your code. It turns the function into one logic formula, and a solver searches that formula for any paid that breaks the assert.
Use Bounded Checking for: code that reads untrusted bytes, arithmetic on sizes and offsets, and unsafe blocks.
4. Full Proof (Verus)
Kani has one weak spot: loops. It copies the loop body into its formula once per iteration, so a longer list means a bigger formula and a slower check. I ran Kani on a batch refund over a list of payments:
5 payments: 13 seconds
10 payments: 60 seconds
20 payments: 8 minutes
To fix it, use Verus. Verus is a proof tool for Rust. You write the production function inside a verus! block and add rules to it, and ensures is a contract, like a type signature: Verus checks it at build time and removes it from the build. For a loop, you add an invariant, a rule that holds after every iteration. With it, Verus proves the rule for lists of every length in half a second:
⚠️ Every loop needs an invariant, and for complex code the invariants are longer than the code. That’s why teams use Verus for small, critical modules and Kani for the rest.
Use Full Proof for: small cores where one bug costs millions, like auth rules, ledgers and crypto.
Other stacks: Dafny proves code and compiles it to C#, Java, Go, Python and JavaScript. Lean and Rocq are proof languages for math and code, and Anthropic’s proofs are written in Rocq.
5. Design Checking (TLA+)
Levels 1 to 4 check one function against its inputs. Some bugs only appear when two requests run in parallel, like a double click on “Refund”. The web server then runs this handler twice, once per request:
TLA+ is a tool for finding bugs in the order of steps, like this double refund. You write a model of the handler in PlusCal, a pseudocode language. Each label is one step, and TLC, the TLA+ checker, runs the steps of both requests in every order:
☝️ You don’t need to learn PlusCal: Opus 5.5 writes the model from your handler, and TLC checks it. You review one line, the rule.
TLC finds the bug in under a second. The handler checks the flag in one step and saves it in another, so both requests read refunded = false and both send the money.
The fix checks and saves the flag in one SQL UPDATE, and sends the money only when it changed a row:
The database runs two updates of the same row one after the other, so the second request changes 0 rows and sends nothing. In the model, the fix merges Load and Send into one label, and TLC finds no order of steps that breaks the rule.
Use Design Checking for: retries, queues, webhooks, locks, caches and state machines.
Formal Verification with AI Agents
In the past, formal verification cost too much engineering time: writing the proof took far longer than writing the code. Coding agents remove that cost. Writing a proof is trial and error, and the checker says yes or no to every try, so an agent can do months of human proof work without a person reviewing it.
But agents also cheat to get a green run: they weaken the rule, or add a line that tells the checker to skip a case, like kani::assume. Four guards stop that:
You write the rule. The agent writes the code and the proof, never the rule.
A hook blocks shortcuts. A Claude Code hook rejects edits to the rule and new lines that skip a case.
CI runs the checker. A required check blocks the merge when the proof fails.
Plant a bug. Break the code on purpose. If the check stays green, the rule is too weak.
I packed these guards into three open-source skills for Claude Code, Codex and Cursor: property-testing for level 2, bounded-model-check for level 3 and model-check-design for level 5. Get them at github.com/dmoka/skills.
Final Thoughts
Your agent writes code faster than you can review it, and its tests check only the inputs it thought of. Kani checks every input up to a bound, Verus proves the rule for every input, and TLC checks every order of steps.
If you want to master agentic testing, check out my recent AI Agent Engineer course.
Last 24 hours to save $75.
Click here to get instant access →
Craft Better Software.
















