# How to Test AI-Generated Code | Yahya Erturan

Canonical: https://yahyaerturan.com/en-GB/blog/testing-ai-generated-code/
Language: en-GB

AI-assisted development

AI Writes the Code, Developers Own Quality

Good software is tested in real-world conditions. Developers own the test scenarios, product promises and release decision.

Yahya Erturan · About 12 min read Published 13/11/2026 Last updated 26/11/2026

 Plan an online meeting ↗
 All articles ↗

You can delegate coding to AI. I see the developer’s responsibility as deciding how the product should behave under different conditions and checking that it actually does. The gap between a working application and a good one often comes down to the quality of that verification.

In brief

Start with acceptance criteria agreed by the people responsible for the product.

Check the interface, the saved state and the side effects as parts of the same journey.

Base release approval on risk, observable evidence and a tested recovery plan.

Test scenarios start with real use

AI can write the tests. Developers should define the expected behaviour with the product team. I look at support requests, past defects and the conditions in which people use the application. How does an operation resume if the connection drops? Does pressing the same button twice change the outcome? Can someone working with older records carry on after the update? Those answers belong in the acceptance criteria before coding starts.

Test the browser, layout and copy together

Browser tests should verify form submission, keyboard navigation and recovery after an error in supported browsers. Visual tests should catch overflowing text, overlapping elements and hidden buttons at different screen sizes. Screenshot comparison detects a change. Developers decide whether it is acceptable.

Every line of interface copy makes a claim about the product. A success message should describe the actual outcome. Feature copy should stay within the product’s scope when promising guarantees or timeframes. An error message should tell users what they can do next. Internal paths and stack traces belong in the team’s logs.

When reviewing translations, I check that every language preserves the meaning and the limits of what is promised. Buttons, emails and error messages should use consistent terms. Date and number formats, longer translations and right-to-left layouts should be tested on the actual screens and within the relevant flows.

Verification from real-world use to release

Define the scenario and acceptance criteria

 Test the interface on supported devices and in supported languages

Browser behaviour

Visual layout

Copy and scope of commitments

Translation and localisation

Verify the end-to-end outcome in the test environment

Review findings and make the release decision

Follow the flow from start to finish

Completion on screen is one link in the chain. In an end-to-end test I follow the user from the first action to the final outcome. Was the record saved correctly? Does the authorised person see the right status? Did the expected notification arrive? Does retrying a failed step create a duplicate record or a second notification? The outcome the user sees should match what the system actually did.

Reliable tests need a reliable environment

The test environment should resemble production where it affects the outcome. The data schema, permission roles and integration settings should allow the same behaviour to be exercised. Representative test data, separate accounts and external services’ test modes make scenarios safe to repeat. Knowing the version, data and step involved in a failure is essential to fixing it.

Running the tests is part of the work. Developers also track the results, investigate failures and retest affected flows after a fix. For me, releasing means being able to trust that the report covers the situations users will face. Good software comes from the engineering work that builds and maintains that trust.

Does a document approval screen really work?

Suppose I ask an AI assistant to draft a document approval interface. It adds a button and displays a success message when the server returns a positive response. That covers the straightforward path. I first write down the governing rule. The document must be awaiting a decision, the reviewer must hold a valid invitation, and an accepted decision must create exactly one audit entry. Once those rules are settled, we can decide where the button goes and how it looks.

I start with a sentence. “When an authorised reviewer approves a pending document, it is marked as approved, the actor and time are recorded, and the owner receives one notification.” That gives us three pieces of evidence. The browser shows the final status, the database confirms the recorded decision, and the notification queue contains a single item. If something is missing we can name the broken part. The processing trace tells us as much as the screenshot.

A timeout reveals more about the rules. The server may save the decision immediately before the connection drops. If the browser displays a generic failure, the person may try again. Does a retry create a second decision? Does reopening the page show the correct status? An operation key can identify repeated requests and let the server return the outcome it already recorded. A regression test should show that repeating the same operation leaves the notification count unchanged.

Two reviewers could also open the same pending document without knowing about each other. I specify which transition is permitted when their decisions arrive moments apart. If only one decision may succeed, the other reviewer sees the updated state and the audit trail tells a coherent story. Two separate browser sessions or two controlled requests triggered together provide firmer evidence than sequential clicks in the same tab.

The message is part of the promise the product makes. It can say “Processing your decision” while the server is working, or “Preparing notification” while an email remains queued. If we say “Document sent”, we need to agree which document, who received it and what state the operation reached. An assistant can draft short, clear copy. The product team and I establish what the wording commits us to.

How I choose test layers by risk and cost

I choose the test layer closest to where the behaviour happens. A pure decision rule is suitable for a quick unit test. Agreeing database state and audit entries requires an integration test with a database. Opening the invitation, seeing the document and understanding the final result call for a browser test. These layers complement one another and help us diagnose the fault without waiting for a slow end-to-end suite every time.

A single browser journey can cover the essential path without testing every date, permission and document combination. It is often easier to represent the decision table as data and run it quickly. A pending document with a valid invitation can receive a decision. A cancelled document might remain viewable but reject any decision. An account without an invitation is checked before the application's decision logic runs. When policy changes, the table helps the team update the code and documentation together.

Example test portfolio for a document workflow

Illustrative plan. Bars show the number of tests run in this example. They do not represent percentages, timings or a recommended coverage ratio.

Unit tests 10 scenarios

Cover state transitions, missing fields and the permission decision table.

Integration tests 5 scenarios

Check persisted state, audit history and the notification queue together.

Browser tests 3 scenarios

Exercise the invitation, successful decision and recovery after an error as user journeys.

I also record the effect of a failure. A poorly aligned button can make the page look untidy. A keyboard user who cannot reach the approval control cannot complete the task. If the wrong person is recorded as the decision maker, an audit becomes unreliable. A simple failure count treats these situations alike. Agreeing what stops a release and recording the most serious open finding makes the numbers more useful.

Updating a reference screenshot is easy. Understanding the change requires a closer look. An assistant may have adjusted padding around a button. On a phone that could push an error message below the control or make Turkish and German labels wrap. If some of the difference is intentional, I ask the reviewer to record the device, language and screen state they inspected. Stable clocks and fixture data keep accidental differences from obscuring the real change.

I use automated accessibility checks, then walk through important paths with a keyboard. I check where focus moves when a dialog opens, which control receives it when the dialog closes, whether the error identifies the right field, and whether a visible control has a usable name. At a critical point, colour or motion alone may leave someone unsure about their next step. A brief explanation can help people continue without asking for support.

How to review a test written by an AI assistant

I give the assistant the business rule and known failures. The brief includes supported browsers, the integration boundary, suitable fixture data and the expected end state. I may ask it to list scenarios before writing the tests. When a change touches unrelated files or relaxes an existing assertion, I read the diff and find out which wrong results the test can actually catch before approving it.

One useful exercise is to introduce a small controlled fault in the test environment. I might remove the document status from the success view or make a known user action create two notification records. If the test still passes, it is missing evidence we need. After strengthening the test, I restore correct behaviour and check that it passes again. An existing defect gives us a similar opportunity if the test fails against the version that contained it.

The test should express a promise to the user or to another component. The number of times a helper was called can be useful in a unit test. That number on its own says little about the whole customer journey. In browser tests I usually check the visible state, a clear message, or the navigation triggered by the person's action. A CSS class or DOM order can change while the promise stays the same.

Some failures appear only under load or during repeated runs. I start by looking for an observable sign that work has completed. After pressing the approval button, I wait for the status to appear or for the notification record to show up in the test inbox. If runs share an account or a document, I give them separate fixtures. Increasing retry counts can help diagnose a pattern. A lasting improvement still depends on finding what caused it.

A test report is useful when someone can investigate the failure later. For each critical check I want the build identifier, the starting fixture and the first failing step. Troubleshooting goes faster when the screenshot, browser trace and application logs share an operation identifier. I use test accounts and representative data to keep personal records and session credentials out of those artefacts. We also agree how long diagnostic records need to be retained.

Making the release decision repeatable

A product owner can clarify the acceptance criteria. A developer can provide evidence for data and permission changes. A designer or tester can confirm that focus order and failure messages make sense on a real device. Small teams can cover several roles with one person. A second reviewer is particularly useful when a release affects payments, personal information or records that could be lost.

I plan what I will watch after release. For our document example that could mean decision success rate, multiple decisions on one document, slow notification delivery and recurring support reports. I attach a threshold, observation window and person responsible to each signal. The team should know in advance who can roll back the release, switch off the feature or pause processing if a signal moves outside the agreed range.

The recovery plan can be rehearsed. Can we deploy the last stable build? Did this release create records that the old build cannot read? What happens to queued work when we resume it? A mobile build already in a store or a cached web app may be slow to update. The server may have to support both versions for a while. I put that decision in the release notes so the team knows where to find it during an incident.

I also track the work involved in keeping tests useful. Total tests written says little about how quickly we catch a critical failure, how often a suite fails without a product fault, or how many issues return after release. When a team pilots an AI tool, I choose a small workflow and keep the acceptance criteria fixed. Fast initial drafts can cost more in review and repair. The comparison should include time spent meeting the same definition of done.

I revisit the acceptance criteria a week after release. If support hears from people who interpreted “Processing the document” as confirmation, the text and the observable state need another look. Sometimes a valid decision eventually reaches the database while the customer still experiences a delay. Adding that delay to a monitoring view gives context to the test result. Keeping the support report, reproduction steps and fixing release together also strengthens the context we give an assistant next time.

Frequently asked questions

How should I test code written by AI?

Write down the expected behaviour and the risk. Start with fast rule checks, test data and service boundaries through integrations, and observe the critical journey in a browser. Check that the test passes against the correct behaviour and fails against a controlled fault.

Should an AI-written test be reviewed too?

Yes. An assistant can copy existing incorrect behaviour or assert too little. A test that accepts the wrong outcome offers weak evidence about the business rule.

Does every feature need an end-to-end test?

Use selected journeys for important boundaries such as sign-in, permissions, payments and notifications. Test small decision rules directly and use integrations to verify the exchange between components.

Does 100% line coverage guarantee a safe release?

Line coverage shows which code ran. You still need evidence for expected data, failure modes, devices, permissions and the result of repeating an operation.

When is a screenshot comparison useful?

Use it for narrow layouts, long translations and shared components that affect several pages. Review the changed region and the relevant screen state before accepting a new reference image.

Should I copy real customer data into a test environment?

I use representative synthetic records. Old and new data shapes, user roles and boundary values can be recreated without using an actual customer's information.

Is it enough to simulate external services in tests?

Simulating provider responses makes fast tests useful. I also check important contracts against a provider's test environment or published interface definition to catch mismatches earlier.

How should I handle an intermittently failing test?

Record the data, timing and dependencies at the failure. Isolate fixtures between concurrent runs and wait for an observable outcome. Reruns help investigate a pattern and the cause still needs a fix.

Which checks matter in multilingual interfaces?

Test local formats, text expansion, Chinese line breaks and Arabic right-to-left layouts. The control, email and error message should describe the same operation in every language.

Who should approve a release?

Give the product behaviour and ongoing operation clear owners. The designated approver should understand critical test results and confirm the recovery plan before agreeing to ship.

Where do I start with test automation?

Choose a frequent, repeatable journey with clear customer impact. For a document workflow, automate opening the invitation and making a decision, then add fast tests for important state transitions.

How can I measure the AI assistant's contribution?

Measure total time from first draft to accepted change. Include review, repairs to incorrect tests and reopened issues when assessing whether the pilot saved work.

Related articles

AI and good software engineering

Delivery barriers in small software teams

Don’t miss new articles

Would you like an email when a new blog article is published?

 Follow via RSS ↗
