Using AI assistants for code review, unit test generation and documentation: where they help, where they mislead, and how to verify AI tests (mutation testing, breaking the code), AI review comments and generated docs.
AI is a strong first pass, never the final check.
The trade-off: minutes saved on drafting against the risk of false confidence, so verification is part of the workflow.
"I use AI in all three places, but always as the first pass. For code review, an AI reviewer such as Copilot code review reads the diff and flags the mechanical things quickly: a missing
usingon anHttpResponseMessage, a nullable dereference, acatchthat swallows the exception, an N+1 query in a loop. That frees the human reviewer for what the model can't judge: does this match the domain rule, is this the right boundary, will this hold at our load. Importantly it only comments; our branch protection still requires a human approval, and the author must resolve or reject each AI comment with a reason.For tests, it's brilliant at scaffolding: the fixture, the builders, a first list of edge cases I might not have thought of. Where it goes wrong is that a model generating tests from the implementation writes tests that pass against the implementation, bugs included. I've seen suites with 90 per cent coverage where half the tests only asserted that a mock was called. So I write or check the cases from the requirement, then I break the code on purpose, flip a
<to<=, and see if a test fails. On important code we run Stryker.NET, and the mutation score tells us whether the tests actually detect changes.Documentation is the easiest win: XML doc comments, a README for a new service, the skeleton of an ADR. The mistake I see is publishing it unchecked, because the model will describe behaviour the code doesn't have, like a retry policy that was never configured. My rule is simple: AI drafts, a human verifies, and the verification is visible in the PR."
| Use | Saves time when | Wastes time when |
|---|---|---|
| AI code review | Mechanical issues, big diffs, consistent rules from instructions | It floods the PR with style nitpicks or false positives |
| Test scaffolding | Fixtures, builders, parameterised cases | Tests are generated from buggy code and enshrine the bug |
| Edge-case brainstorming | Inputs, boundaries, concurrency, time zones | Nobody checks the list against the requirement |
| Characterisation tests | Pinning legacy behaviour before refactoring | You confuse "current" with "correct" behaviour |
| Docs and ADR drafts | Structure and first wording | It invents configuration or behaviour |
| Output | Check |
|---|---|
| AI review comment | Reproduce or reason it through; resolve with a reason; human approval still required |
| Generated tests | Cases traced to requirements; break the code on purpose; Stryker.NET mutation score |
| Generated docs | Run the documented commands; compare config keys and defaults with the code |
After enabling AI review on [our API repo of ~120k lines], median time to first review comment fell from [4 hours to minutes], and human reviewers spent their time on design. A Stryker.NET run on the AI-generated tests for [the pricing module] showed a mutation score of [48%]; after rewriting the weak tests from the requirements it reached [81%] and caught [a rounding bug] the original suite had passed.
Checks that the candidate uses AI to speed up review, testing and docs while keeping verification and accountability human.
Green flags
Red flags
The reviewer gets the diff plus surrounding files and repo instructions, and (in newer agentic reviewers) can call tools to read more of the codebase or run analysis. It produces line comments, sometimes with suggested changes. As of November 2026, Copilot code review can be requested on a PR or run automatically, reads custom instructions, and leaves comment reviews rather than approvals, so it does not satisfy a required-reviewer rule. Other tools differ, so check how yours interacts with branch protection.
PR opened ──► AI reviewer (diff + context + instructions) ──► comments / suggestions
│
author fixes or rejects with reason ◄──────┘
│
human reviewer: design, domain, risk ──► approve (required by branch protection)
It is strongest on local, pattern-shaped issues and weakest on cross-cutting ones: whether a cache invalidation is complete, whether a transaction boundary is right, whether a change breaks a consumer in another repo. Quality also varies with how much relevant context it can see: a tidy codebase with clear names and instructions gets better reviews than a tangled one.
If the model sees the implementation, the easiest tests to generate are ones that describe it. Three classic failures:
mock.Verify(x => x.Save(It.IsAny<Order>())) with no check of what was saved.Coverage measures lines executed, not behaviour checked. A line can be covered by a test that asserts nothing.
Stryker.NET makes small changes (mutants) to your code: < to <=, && to ||, removing a statement, changing a constant. It runs the tests for each mutant. If a test fails, the mutant is killed; if all pass, it survived, which means no test checks that behaviour.
source ──► mutant 1 (< becomes <=) ──► run tests ──► fail = killed (good)
──► mutant 2 (remove call) ──► run tests ──► pass = survived (gap)
mutation score = killed / (killed + survived)
It is slow on big codebases, so run it on critical modules, or incrementally on changed files in CI (--since).
Models write fluent prose quickly, which makes wrong statements convincing. Typical errors: default values, configuration keys, retry and timeout behaviour, and steps that worked in an older version. Treat docs like code: they go in the PR and the reviewer checks them against the code and by running the commands.
Every AI review costs tokens or premium requests and, more importantly, reviewer attention. A reviewer that leaves 30 low-value comments trains people to ignore it, including the one comment that mattered. Practical controls:
| Control | Effect |
|---|---|
Instructions: "don't comment on formatting; dotnet format handles it" |
Removes the biggest noise source |
| Instructions: "prioritise security, data loss, concurrency, money" | Puts severe findings first |
| Let analysers own what they can (nullable, CA rules) | Deterministic checks beat probabilistic ones |
| Track the share of AI comments that lead to a change | Tells you whether it's worth the attention |
| Author resolves every AI comment with a reason | Rejections become feedback for the instructions |
dotnet tool install -g dotnet-stryker) and run it on one project; read the surviving mutants.async void and an undisposed HttpResponseMessage; note what it finds and misses.An anti-pattern test of the kind assistants often generate, next to tests derived from the requirement, plus a Stryker.NET configuration that proves the difference.
namespace Pricing.Tests;
public sealed record OrderLine(decimal UnitPrice, int Quantity);
public sealed class GstCalculator
{
// Requirement: GST is 10% of the order total, rounded once to the cent, half away from zero.
public decimal GstFor(IReadOnlyList<OrderLine> lines) =>
Math.Round(lines.Sum(l => l.UnitPrice * l.Quantity) * 0.10m, 2, MidpointRounding.AwayFromZero);
}
public sealed class GstCalculatorTests
{
// ANTI-PATTERN (shown on purpose): executes the code but asserts almost nothing.
// Stryker.NET mutants such as 0.10m -> 0.20m or AwayFromZero -> ToEven all survive it.
[Fact]
public void GstFor_returns_value() =>
new GstCalculator().GstFor([new(10m, 1)]).Should().BeGreaterThan(0);
// GOOD: exact expected values traced to the requirement.
[Theory]
[InlineData(10.00, 1, 1.00)] // the basic rule: exactly 10%, kills any change to the rate
[InlineData(0.05, 1, 0.01)] // boundary: 0.005 must round AWAY from zero (banker's rounding gives 0.00)
[InlineData(0.00, 3, 0.00)] // free items: no negative or phantom GST
[InlineData(0.15, 3, 0.05)] // multiply before rounding: 0.045 -> 0.05; rounding per unit gives 3 x 0.02 = 0.06
public void GstFor_is_ten_percent_rounded_half_away_from_zero(double price, int qty, double expected) =>
new GstCalculator().GstFor([new((decimal)price, qty)]).Should().Be((decimal)expected);
// GOOD: totals across lines are rounded once, not per line.
[Fact]
public void GstFor_rounds_the_total_not_each_line() =>
new GstCalculator().GstFor([new(0.04m, 1), new(0.04m, 1)]).Should().Be(0.01m); // 0.008 -> 0.01; per line gives 0.00
}
// stryker-config.json: run on the pricing project only, fail CI below 70%
{
"stryker-config": {
"project": "Pricing.csproj",
"thresholds": { "high": 85, "low": 70, "break": 70 },
"reporters": ["html", "progress"]
}
}
Verify that a method was called). Why it is wrong: they pass even if the saved data is wrong. Instead: assert the outcome or state.AI moves the bottleneck from writing to verifying. A team that adopts AI review and test generation without strengthening verification (requirements-based cases, mutation testing on critical paths, human approval) ends up with more code and more tests but less confidence. The senior move is to put the verification into the pipeline so it isn't optional.
| Use | When it fits | Cost | When not to |
|---|---|---|---|
| AI first-pass review | Every PR, tuned by instructions | Tokens; reviewer attention on false positives | As the only reviewer on security or money paths |
| AI test scaffolding | New code with clear requirements | Review of each case | As proof that legacy code is correct |
| Mutation testing | Pricing, auth, rules engines | CI time (minutes to hours) | The whole monolith on every commit |
| AI doc drafts | READMEs, XML docs, ADR skeletons | Verification time | Compliance or security docs without expert review |
Measure with the share of AI comments that cause a change, mutation score on critical modules and escaped defects per release.
A good code prompt reads like a good ticket for a capable contractor who has never seen the repo:
Result<T> type in Shared/Result.cs").Then ask for edge cases and tests first, review them, and only then ask for the implementation. When it's wrong, paste the actual compiler error or failing test instead of "try again". Rules you repeat go in an instructions file. The trade-off: a longer prompt costs a minute, a vague one costs a review cycle.
Good enough means the tests would notice if your change broke something. Check three things. Coverage of the change area (not the codebase): every branch you'll touch is executed, including the input grid of any golden master, the set of input combinations whose outputs you snapshot, which should include boundary values. Sensitivity: run Stryker.NET on the changed files only (--since) and explain or kill surviving mutants, or break a line by hand and confirm a test fails. Reliability and speed: run the new tests repeatedly to prove they are deterministic, and keep them fast enough to run in the PR pipeline on every commit, because a safety net that is flaky or only runs nightly won't protect the change.
AI-generated code carries the usual risks plus some new ones:
true, MD5, or a missing [Authorize].Control it with the gates you already need (SAST, secret scanning, dependency review, human approval) plus package source mapping, lock files and allow-lists, content exclusions and a data policy. The trade-off: a little friction on new dependencies in exchange for closing the cheapest attack path.
How to tell it (STAR)
**S:** At [company], our pricing service had [92%] coverage, mostly from AI-generated tests, and a discount-stacking change still overcharged [customers] for [two days]. **T:** I was asked to fix it and work out why the tests didn't catch it. **A:** I reproduced it with a test from the support ticket, then ran Stryker.NET: the mutation score was [46%], because most tests asserted only that a value was positive. I rewrote the tests from the business rules with exact values and boundaries, and added a mutation-score gate in CI for pricing and tax. **R:** The score went to [83%], the gate has since blocked [3] weak PRs, and we've had [no] pricing defects escape in [the following two quarters].
Last updated 23 Nov 2026.