Testing and code review with AI
Mid / SeniorGenerating meaningful tests, using AI as a first-pass reviewer, and avoiding tests that only restate the code.
Created 19 October 2026
9 concepts · detail hidden
01Glossary — terms used in this page
#c-glossary-terms-used-in-this-page- Property-based testing — asserting invariants over many generated inputs rather than fixed examples.
- Mutation testing — deliberately injecting bugs to check whether the test suite catches them.
- Characterization test — a test that records current behavior of legacy code before changing it.
- SAST (Static Application Security Testing) — analysis of source code for vulnerabilities without running it.
- Flaky test — a test that passes and fails nondeterministically without code changes.
02Generating unit tests that test behavior
#c-generating-unit-tests-that-test-behaviorTests derived only from the implementation tend to assert what the code does, bugs included. Generate tests from the spec or acceptance criteria, or ask for edge cases (empty, null, boundaries, concurrency, error paths) first and implementation-specific tests second.
03Validating generated tests with mutation testing
#c-validating-generated-tests-with-mutation-testingA high coverage number from AI-written tests proves little. Mutation testing shows whether the tests fail when the code is broken; surviving mutants point at weak assertions the model should strengthen.
04Test-first loops with an agent
#c-test-first-loops-with-an-agentWrite or generate failing tests, then let the agent implement until they pass. The failing tests are an executable spec and bound the agent’s freedom to drift. Watch for the agent “fixing” a failing test by weakening or deleting it instead of fixing the code.
05Characterization tests before AI refactors
#c-characterization-tests-before-ai-refactorsFor legacy code, have the model generate tests that capture present behavior, review them for sanity, then refactor with the safety net in place.
06Triage of failing tests and flaky builds
#c-triage-of-failing-tests-and-flaky-buildsGive the agent the failure output and let it propose a cause and a minimal fix. For flaky tests it can spot common culprits (shared state, time, ordering, unawaited async work), but confirm by rerunning rather than trusting the explanation.
07AI as a first-pass code reviewer
#c-ai-as-a-first-pass-code-reviewerAutomated reviewers summarise a PR, flag likely bugs, missing tests, security smells and style drift. Use them to catch the cheap things so human reviewers spend attention on design, naming, and domain correctness. They complement, not replace, linters and SAST, which are deterministic.
08Reviewing AI-generated diffs
#c-reviewing-ai-generated-diffsGenerated changes are large and fluent, which invites skimming. Keep PRs small, require the author to explain the change, check for unrequested edits (touched unrelated files, removed tests, loosened assertions), and look specifically for deleted or weakened checks.
09Review by a second, independent agent
#c-review-by-a-second-independent-agentA fresh session with no memory of the implementation reviews with different blind spots than the one that wrote the code. Asking the author-agent to review its own work mostly confirms its own assumptions.