You can let an AI coding agent write tests for your code, but a test is only worth something if it checks the right behavior. Tests are small pieces of code that check whether your code does what it should. An AI coding agent is a tool that reads and edits your project’s files and runs commands, such as the command that runs your tests. Claude Code and GitHub Copilot are AI coding agents, and so is Cursor.

The agent can do a lot of the work, but the last check stays with you. Microsoft’s guide for VS Code, its code editor, on test-driven development with AI suggests the same order as the steps below.

Step 1: Let the agent look at your test setup

The agent first needs to know how your project runs its tests. Before it edits anything, ask it to look through the project and tell you three things:

  • The test framework the project uses (for example PHPUnit, Jest or pytest)
  • The folders where the tests live
  • The command that runs them

Tell it not to edit files or install anything during this step.

Then run that command yourself and write down which tests already fail. This list is your baseline. If a test fails later, check the list to see whether it was already failing or the new tests broke it.

Step 2: Agree on what the code should do

An agent can only write a good test if it knows what the right result is. Start small, with one function or one module (a file or a group of files that does one job). Then tell the agent what that code is supposed to do. This is the requirement.

Ask the agent for a list of test cases before it writes any code. A test case is one situation the test checks, like one input and the result you expect for it. Compare each case with the requirement instead of the current code. If a test only copies what the code does now, it will copy existing bugs too.

For a function that takes input and returns a result, ask for three kinds of cases:

  • Normal input
  • Values at the edge of what the function accepts, like 0 or an empty list
  • Input the function should reject, and the error you expect for it

Here is a prompt you could give the agent for this step:

Read the existing tests in tests/Unit and propose test cases for the discount calculation in app/Billing/Discount.php. The requirement: discounts can’t be higher than the order total. Include edge cases and invalid input, and list anything that’s unclear. Don’t edit any files yet.

Step 3: Have it add tests only

When you’re happy with the list of cases, ask the agent to write only the tests. Tell it to use the test framework and helper code your project already has, without installing new packages. It also shouldn’t touch your production code, which is the code that runs in your product.

Check two things in each new test:

  • It calls the code you want to test and checks a result you can see. That can be the value a function returns, or a record saved in the database.
  • The expected result comes from the requirement, or someone wrote it out by hand in the test. Some tests call the function they’re testing to calculate the expected result. If that function has a bug, both results will be wrong in the same way, and the test will still pass.

If a new test uncovers a bug in your code, fix it in a separate change.

Step 4: Run the tests, small first

Don’t start with all the tests at once. Start with the smallest command that runs the new tests, such as the command for a single test file. Ask the agent to tell you:

  • The command it ran
  • How many tests passed and how many failed
  • Which tests were skipped or didn’t run at all

When a test fails, find out why before you accept the change. Maybe the test expects the wrong result or has a setup mistake. Or maybe your production code has a bug.

Watch whether the agent makes a failing test pass by making the test weaker. It can do that in three ways:

  • It loosens an assertion. An assertion is the line in a test that checks the result.
  • It changes the result a test expects, even though no requirement says it should.
  • It marks the test as skipped, so the test doesn’t run.

Once the new tests pass, run the wider test suite (a larger set of your project’s tests) to see whether anything else broke.

Step 5: Review what the tests check

Passing tests still don’t tell you what they check. To see that, read the diff (the list of lines the agent changed) and the test output yourself.

Many tests use mocks. A mock is a stand-in for something your code depends on, like a payment service or an email sender. If a mock sits in the wrong place, it can replace the very code the test is supposed to check. Then the test checks the mock instead of your code.

When you read the diff, check three things:

  • The assertions match the behavior you agreed on in step 2.
  • No production files changed.
  • No mock replaces the code you wanted to test.

A coverage report shows which lines of code ran during the tests. It doesn’t show whether the assertions are right.

Can you trust tests an AI agent writes?

Three studies from 2026 looked at this question from different sides. The studies count commits. A commit is one saved change in a project’s history.

Study What it looked at What it found
Testing with AI Agents (MSR 2026) 2,232 commits that changed tests, in open source projects AI wrote 16.4% of the commits that added tests. Its tests raised coverage about as much as tests written by people.
Are Coding Agents Generating Over-Mocked Tests? (MSR 2026) 1,254,878 commits in Python, JavaScript and TypeScript repositories Agents added or changed tests in 23% of their commits. Other commits did that in 13% of cases. When agents changed tests, they added mocks in 36% of those commits. In other commits that changed tests, it was 26%.
Rethinking the Value of Agent-Generated Tests How six AI models fixed GitHub issues from SWE-bench Verified When the models wrote more tests or fewer tests, they didn’t solve significantly more or fewer issues. Their tests often printed values but didn’t check whether the values were right.

Judge each test by the behavior it checks. Test counts and coverage numbers don’t tell you that.

Can an agent do this as a task in GitHub?

Some agents take a task and come back with a pull request. A pull request is a set of proposed changes on GitHub that you review and merge in. GitHub Copilot’s coding agent works this way. So does Vroni, an AI coding agent for GitHub repositories.

Vroni reads the project and uses the test framework and test folders it finds there. It writes the tests and runs the checks your project already has. If something fails, Vroni fixes it. Then it opens a pull request with a summary. Vroni never merges a pull request and never pushes to your main branch, so you still do steps 4 and 5 yourself.

Vroni works only with GitHub. The environment Vroni works in has no MySQL or PostgreSQL database server and no Docker. You can’t give Vroni API keys or an .env file. Test suites that don’t need any of these run fine, and so do test suites that use SQLite.

You pay for the minutes Vroni works on a task. The Solo plan costs $299 a month (€249 in Europe) and includes 2 hours. The Team plan costs $1,199 a month (€999) and includes 10 hours. The Vroni docs on writing tests have example tasks.