DEV Community

Ashkan Rajaee
Ashkan Rajaee

Posted on

Testing AI-Generated Code: A Practical QA Strategy for Delivery Teams

A developer on a client project asks an AI assistant to write a function that calculates late fees on overdue invoices. In under a minute, the assistant produces clean, well-named code with comments. The developer reads it, it looks right, the happy-path test passes, and the change ships. Three weeks later the client's finance team notices that invoices due on the last day of the month are being charged a fee one day early. The code handled dates in a way that looked reasonable and was quietly wrong.

Nobody on that team was careless. The code was readable and the test was green. The problem is that the testing habits most teams built over the years assumed a human wrote every line, and that a human who wrote it also understood it. With AI assistants writing a growing share of the code, that assumption no longer holds.

Earlier in my career, as a partner, I helped grow a software consulting company from about $6M to $60M in under three years, and later I founded and ran a fully remote consultancy. Quality was always the thing clients judged us on, long after they forgot the rate card. Here is how I think a delivery team should adjust its testing when much of the code comes from an AI assistant.

Why AI-Generated Code Needs a Different Testing Mindset

AI assistants are very good at producing code that looks correct. That is exactly what makes testing it different.

When a person writes a tricky piece of logic, they usually struggle with it a little, and that struggle leaves clues. They ask a question in the team channel, leave a comment about an edge case, or write an extra test because they were unsure. AI output arrives confident and polished, with no record of what was hard. The reviewer and the tester have fewer signals about where to look.

AI output also tends to fail in patterns. Knowing those patterns tells you where to focus your tests.

Where AI Output Tends to Fail

From what I have seen on delivery teams, AI-generated code most often goes wrong in a handful of places:

  • Edge cases and boundaries. Empty lists, zero values, the last day of the month, leap years, time zones, very large inputs. The assistant writes for the common case unless told otherwise.
  • Assumptions about the system around it. The code may assume an API returns a field that it does not, or that a database column can never be null. It does not know your system, only systems like it.
  • Plausible but outdated library use. An assistant may call a function in a way that worked in an older version of a library, or invent an option that does not exist.
  • Error handling. AI code often handles the success path well and treats failures lightly: a broad catch block, a swallowed exception, a retry with no limit.
  • Security details. Input validation, permission checks and safe handling of user data are easy to leave out when the goal was simply "make it work."
  • Consistency with the rest of the codebase. The code may solve the problem in a style or pattern that differs from everything around it, which makes later changes riskier.

None of these are exotic. They are the same mistakes people make. The difference is that AI makes them quickly, cleanly and with no visible hesitation.

The Tests to Require Before Merge

A simple, written rule set helps more than good intentions. These are the standards I would ask a delivery team to agree on for any change where an AI assistant wrote a meaningful part of the code.

1. Tests that cover the edges, not just the happy path. For every new function with real logic, require at least one test for empty or missing input, one for a boundary value and one for an expected failure. If the change involves dates, money or time zones, require specific tests for those.

2. Tests written from the requirement, not from the code. The most useful test is one written by reading the ticket or the acceptance criteria, then checking the code against it. Tests written by reading the code tend to confirm what the code does, including its mistakes.

3. Integration tests at the boundaries. Where the new code talks to an API, a database or another service, require at least one test that runs against a realistic version of that dependency. This is where wrong assumptions about the surrounding system get caught.

4. A check that every library call is real and current. Make it someone's job, usually the reviewer, to confirm that the functions and options used actually exist in the version the project uses. Automated dependency and type checks help a lot here.

5. Clear failure behavior. Require a test that shows what happens when the dependency fails: a timeout, a bad response, a missing record. The code should fail in a way the team chose, not by accident.

6. Coverage on the changed lines. Overall coverage numbers can hide gaps. Looking at coverage for the lines that changed in a pull request is a better signal of whether the new code is actually tested.

These rules apply to human-written code too, and that is fine. The point is to make them explicit and consistent once AI output becomes a large share of what the team ships.

Using AI to Help Write Tests, Without Trusting It Blindly

AI assistants are genuinely useful for testing. They can draft test cases quickly, suggest edge cases a tired developer would miss and generate realistic test data. Refusing to use them for tests would waste a real advantage.

The risk is circular. If the same assistant writes the code and the tests, and both are based on the same misunderstanding, the tests will pass and the bug will ship. A few habits break that circle:

  • Ask for edge cases, then judge them yourself. Prompt the assistant to list what could go wrong with a function, then decide which of those cases matter for this client and this system.
  • Write the expected results by hand. Let the assistant draft the structure of a test, but have a person set the expected values from the requirement. That is the part that must not be guessed.
  • Break the code on purpose. Change a condition or remove a check and confirm that at least one test fails. If nothing fails, the tests are not really testing that logic.
  • Keep a human owner for every test suite. Someone on the team should be able to explain what each important test proves.

How This Differs From Code Review and AI Policy

This topic sits next to two others but is its own piece of work. Code review is about a person reading a change and judging its design, readability and fit. An AI coding assistant policy is about which tools the team may use, on which data and with what disclosure to the client. Technical debt is about the shortcuts that pile up over time. Testing AI-generated code is about proving, with repeatable checks, that the code does what the client needs, including in the cases nobody thought about when it was written.

What to Tell the Client

Clients increasingly ask whether their software is being written with AI, and how quality is protected. The worst answer is a vague reassurance. A better one is short and concrete.

Explain that the team uses AI assistants for parts of the work, that every change goes through the same tests and review regardless of who or what wrote it, and what those tests require before merge. If the client has a QA team of its own, offer to share the testing standards so both sides check the same things. Report defects found in testing as part of normal status updates, so the client sees the process working rather than just hearing about it.

Most clients are not worried about AI itself. They are worried about losing control of quality. Showing them the checks is what earns their confidence.

A Hypothetical Example

Here is a made-up scenario. A small team is building a booking system for a chain of physical therapy clinics. The developers use AI assistants heavily, and early on the team notices that several bugs reached the client's test environment even though every pull request had passing tests.

The delivery lead looks at the failures. Almost all of them are boundary problems: appointments that cross midnight, clinics in a different time zone, a patient with no insurance record. The tests had been written mostly by the same assistant that wrote the code, and they checked the normal case well.

The team adopts three rules. Every scheduling change needs tests for time zone and midnight cases. Expected results in tests are set by a person from the ticket. And before merging, the developer deliberately breaks one condition to confirm a test catches it. The delivery lead also shares the new standards with the client's operations manager and adds a short testing section to the weekly status report.

Over the next two months, the number of defects reaching the client's test environment drops sharply, and the client's operations manager starts forwarding the testing section of the report to her own leadership. In this story, the AI did not become less useful. The team simply stopped letting it grade its own work.

What This Will Not Fix

Better testing catches more mistakes. It does not replace understanding. If no one on the team can explain how a critical part of the system works, tests will only tell you that it worked yesterday.

It also will not make up for unclear requirements. If the ticket is vague, a test written from it will be vague too. And it adds some time to each change. In my experience, that time is far smaller than the cost of a client finding the bug first.

Start With Your Next Pull Request

You do not need a new QA department to get this right. Start with the next change that an AI assistant helped write. Ask for edge-case tests, set the expected results from the requirement, add one test at the system boundary and break the code once on purpose to see if the tests notice.

AI assistants have changed how fast code gets written. They have not changed what the client is paying for, which is software that works in the real world, including on the last day of the month. A testing strategy built for AI-generated code is how a delivery team keeps that promise.

If you are adjusting your team's testing for AI-assisted development and want a second opinion on your QA standards, visit https://tdzpro.com.

Ashkan Rajaee is the founder of TDZ Pro. He has spent years building and scaling software engineering teams, including a fully remote software consultancy.

Top comments (0)