Overview

8 Evaluation is king: how to trust code you didn’t write

AI-generated code changes the software workflow because the main problem is no longer producing code, but deciding whether it should be trusted. The chapter argues that generated code behaves like legacy code from the moment it is created: it has no human author to explain intent, no built-in understanding of edge cases, and often looks deceptively polished even when it is wrong. This creates a growing trust deficit, where code can be produced much faster than it can be verified, and where familiar habits like quick review or “works for me” checks are no longer enough.

To close that gap, the chapter presents evaluation as a layered pipeline rather than a single test. Basic gates such as compilation, type checking, linting, dependency scanning, and diff checks catch structural and security issues, but they do not prove correctness. The next layer uses tests as contracts: manual exploration helps form a mental model, unit tests define intended behavior, test-driven prompting turns tests into specifications, and higher-signal techniques like property-based testing, fuzzing, mutation testing, and differential testing are used to attack blind spots and uncover hidden failures. The core lesson is that tests should describe intent, not implementation, and that AI-generated code needs adversarial verification because its blind spots often overlap with the blind spots of the tests humans naturally write.

The chapter then expands evaluation to the system level and production. Design by contract, contract testing, integration tests, and end-to-end tests help ensure the code fits the surrounding architecture and does not silently break other services or workflows. For critical cases, stronger methods such as formal verification, stronger type systems, and SMT solvers offer higher assurance, while runtime verification, observability, canary rollouts, and chaos testing catch the failures that only appear under real conditions. The overarching message is that the developer’s role shifts from code author to trust engineer: someone who knows how to measure uncertainty, choose the right verification method for the risk, and build confidence that AI-generated code deserves to exist.

Impact vs Ease of Implementation.
Example of Approval Request.
Example of Visual Regression Tests.
Modern LLM verification stack.

Summary

  • AI creates a trust deficit: code is produced faster than it can be verified, making evaluation the new bottleneck.
  • Benchmarks like HumanEval and SWE-bench measure isolated problems, not production readiness.
  • Static analysis catches errors AI rarely makes while missing errors AI makes constantly.
  • Unit tests tend to verify the cases AI handles well - the blind spots correlate.
  • Test-Driven Prompting shifts the burden to thinking of edge cases before generation, not after.
  • Code coverage can be gamed when AI generates tests alongside implementation.
  • Property-based testing does not only find bugs in code. It finds the places where you never had a specification.
  • Mutation testing measures test quality - surviving mutants reveal what your tests don't actually verify.
  • Contract testing catches breaking changes AI makes without knowing other systems depend on current behavior.
  • Characterization testing detects collateral damage when AI modifies more than intended.
  • Formal methods provide mathematical proof - and AI is lowering the barrier by automating annotations.
  • Runtime observability turns production into continuous testing where every request is a test case.
  • Verification investment should match system criticality - regeneration can be cheaper than debugging.
  • QA skills become core engineering competencies when code generation is automated.

FAQ

Why does the chapter say AI-generated code is “legacy code” from the moment it is created?Because legacy code is defined as code without tests or without a safe way to change it. AI-generated code has no author to interrogate and no built-in understanding of its intent, so it starts life without the human mental model that makes code easier to trust and modify.
What is the “trust deficit” in AI-generated code?The trust deficit is the gap between how fast AI can produce code and how fast humans can verify that it deserves to exist. As generation speeds up, evaluation becomes the bottleneck, and shipping code without enough verification increases risk and technical debt.
Why is “works on my machine” not enough for AI-generated code?With AI-generated code, passing a few manual checks only proves that specific inputs worked. It does not imply broader correctness, because there is no human intent or mental model behind the code to generalize from one successful example to the next.
Why are compiler checks and type checking useful, but not sufficient?They verify that code is structurally coherent, but not that it does the right thing. A function can be perfectly typed and still implement the wrong behavior, miss edge cases, or fail on realistic inputs.
How can static analysis help evaluate AI-generated code?Static analysis can catch known bad patterns such as unsafe regexes, security risks, and dependency problems. It is fast and scalable, but it only finds issues it has been programmed to recognize, so it cannot prove correctness.
Why can coverage numbers be misleading for AI-generated tests?Because high coverage only means code paths were executed, not that behavior was actually verified. AI can generate tests that exercise most of the code while still missing the edge cases that matter, or even mirror the implementation instead of testing it.
What makes property-based testing especially valuable for AI-generated code?It shifts testing from example-by-example checks to universal properties that should hold for many inputs. This helps expose edge cases, invariants, and failure modes that humans and AI often overlook in example-based unit tests.
Why is mutation testing a good way to test AI-generated tests?Mutation testing checks whether your tests fail when the code is deliberately broken. If many mutations survive, the tests may be passing without really verifying behavior, which is a common problem when tests are generated alongside AI-written code.
How do contract tests and integration tests reduce risk with AI-generated code?Contract tests protect service boundaries by making expectations explicit between producers and consumers. Integration tests go further by verifying that the code works in the real system context, catching issues that isolated unit tests cannot see.
What is the chapter’s main shift in mindset for developers using AI?Move from being a code author to being a trust engineer. Your job is not just to generate code, but to build confidence through layered evaluation, adversarial testing, and explicit verification of behavior, risk, and system impact.

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Vibe Engineering ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Vibe Engineering ebook for free