📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

📚 Interview question

How do you use AI for code review, test generation and documentation? Where does it genuinely save time, where does it waste it, and how do you check its output before trusting it?

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.

Mid-Level Theory Intermediate ai code-review documentation github-copilot mutation-testing test-generation

🎯 Key points

  • AI review is a first pass: catches null checks, missing disposal, swallowed exceptions, obvious bugs; humans own approval
  • Copilot code review leaves comments, it does not approve; required human reviewers stay in branch protection
  • Output quality varies with context: strong on local patterns, weak on cross-file, domain and concurrency issues
  • Generated tests often assert current behaviour (snapshot of bugs) or only verify mock calls
  • Verify tests: derive cases from the requirement, break the code on purpose, run Stryker.NET mutation testing
  • Docs: good first drafts of XML comments, READMEs, ADR skeletons; check every claim against running code
  • Manage noise: instructions to skip style, severity focus, track the share of comments that lead to a change
  • Measure: review turnaround, escaped defects, mutation score, not comment count

⏱ 30-second answer

AI is a strong first pass, never the final check.

  • Code review: tools like Copilot code review catch missing null checks, undisposed resources, inconsistent naming and obvious logic slips in seconds, so humans can focus on design and domain rules. It comments; a human still approves.
  • Tests: great for scaffolding and edge-case lists, risky as proof: generated tests often assert what the code does, not what it should do. Check them by breaking the code or with mutation testing (Stryker.NET).
  • Docs: fast drafts of XML comments, READMEs and ADR skeletons; every statement is checked against the code.

The trade-off: minutes saved on drafting against the risk of false confidence, so verification is part of the workflow.

🗣 Full answer (senior)

How I would answer this in an interview

"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 using on an HttpResponseMessage, a nullable dereference, a catch that 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."


Where it saves time and where it wastes it

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

How I verify each output

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

Production example

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.

🔍 What the interviewer is checking

Checks that the candidate uses AI to speed up review, testing and docs while keeping verification and accountability human.

Green flags

  • Calls AI review a first pass and keeps required human approval
  • Knows generated tests can enshrine bugs; derives cases from requirements
  • Mentions mutation testing (Stryker.NET) or breaking the code on purpose
  • Checks generated docs against running code
  • Measures outcomes, not volume

Red flags

  • "The AI reviewed it, so it's fine"
  • Uses coverage percentage as proof of quality
  • Accepts interaction-only tests
  • No idea how to tell a good test from a bad one

📚 Learn in depth

1. How AI code review works

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.

2. Why generated tests can lie

If the model sees the implementation, the easiest tests to generate are ones that describe it. Three classic failures:

  1. Snapshotting bugs: the test asserts the wrong value the code returns.
  2. Interaction-only tests: mock.Verify(x => x.Save(It.IsAny<Order>())) with no check of what was saved.
  3. Happy path only: coverage looks high, branches that matter are never asserted.

Coverage measures lines executed, not behaviour checked. A line can be covered by a test that asserts nothing.

3. Mutation testing

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).

4. Documentation drafts

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.

5. Managing noise

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

Try it yourself

  1. Ask an assistant to generate tests for a method with a deliberate off-by-one bug; see if any test fails.
  2. Install Stryker.NET (dotnet tool install -g dotnet-stryker) and run it on one project; read the surviving mutants.
  3. Request an AI review on a PR with a planted async void and an undisposed HttpResponseMessage; note what it finds and misses.
  4. Generate XML docs for a class and check every default value it states against the code.
  5. Track for two weeks: AI review comments raised vs comments that led to a code change.

💻 Code

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"]
  }
}

⚠ Common mistakes

  • Mistake: Treating an AI review as the approval. Why it is wrong: it misses design, domain and cross-repo issues, and it can't be held accountable. Instead: keep a required human approval in branch protection.
  • Mistake: Letting the model generate tests from the implementation and trusting green. Why it is wrong: the tests encode the existing bugs. Instead: derive cases from the requirement and check them by breaking the code.
  • Mistake: Using coverage as proof of test quality. Why it is wrong: a covered line may have no assertion. Instead: use mutation testing (Stryker.NET) on critical code.
  • Mistake: Accepting interaction-only tests (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.
  • Mistake: Publishing generated docs unchecked. Why it is wrong: fluent prose makes invented defaults believable. Instead: run the commands and compare config keys with the code.
  • Mistake: Leaving a noisy AI reviewer untuned. Why it is wrong: people learn to ignore all its comments, including the real ones. Instead: tune instructions and drop low-value categories.
  • Mistake: Measuring success by number of AI comments or tests generated. Why it is wrong: volume isn't quality. Instead: track escaped defects, mutation score and review turnaround.

🏛 Senior insight: trade-offs

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.

🔗 Follow-ups the interviewer may ask

  1. When: Candidate mentions asking the assistant for edge cases or tests Why: Checks how they steer generation, not just how they verify it
    How to answer

    A good code prompt reads like a good ticket for a capable contractor who has never seen the repo:

    • Goal: what should be true when done.
    • Context: the files, interfaces and target framework ("ASP.NET Core 10, EF Core 10, our Result<T> type in Shared/Result.cs").
    • Constraints: libraries to use, patterns to follow, what must not change.
    • Example: an existing class in house style.

    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.

  2. When: Candidate mentions using AI to write tests before refactoring legacy code Why: Checks how they judge whether characterisation tests are strong enough
    How to answer

    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.

  3. When: Candidate mentions the AI reviewer missing security issues Why: Checks awareness of AI-specific security risks in generated code
    How to answer

    AI-generated code carries the usual risks plus some new ones:

    • Insecure patterns: models reproduce what's common, such as string-built SQL, a certificate callback that returns true, MD5, or a missing [Authorize].
    • Hallucinated packages: the model names a NuGet or npm package that doesn't exist, and attackers register those names (slopsquatting).
    • Licence exposure from suggestions matching public code, and data leakage when secrets or personal information go into prompts.
    • Poisoned context: instruction files or docs that steer agent mode into unsafe edits or commands.

    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.

🛠 Real-world problems: how you handle them

AI-generated test suite with high coverage missed a pricing bug
Situation
[A pricing service] in [an e-commerce platform] had a test suite largely generated by an AI assistant, showing [92%] line coverage. A change to discount stacking shipped and [some customers] were charged the wrong total for [two days].
Signals
Customer complaints and refund requests; finance reconciliation showed a [0.4%] revenue variance; all tests and the AI review had passed; coverage unchanged.
Investigation
Reproduced the wrong total with a unit test from the support ticket. Read the existing tests: most asserted `BeGreaterThan(0)` or only verified repository calls. Ran Stryker.NET on the pricing project: mutation score [46%], with surviving mutants on every discount comparison. Checked the PR: the AI review had commented on naming, not the logic.
Resolution
Hotfixed the stacking rule with a requirement-based test first. Then rewrote the pricing tests from the business rules with exact expected values and boundaries, raising the mutation score to [83%].
Prevention
Stryker.NET in CI for the pricing and tax projects with a break threshold of 70; a PR checklist item "tests trace to requirements"; repo instructions telling the AI reviewer to focus on logic and money; a team rule that AI-generated tests are reviewed like production code.

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].

↩ Usually asked after

More in AI-Assisted Development

Last updated 23 Nov 2026.

🌐 Sangam's Webring

⏪ Previous 🏠 Main Next ⏩
💬 Chat with me