Tasks
AI Testing Agent: Agents, Add-ons, Prompts
Checked 2026-10-31
Loading poll...
Use an AI testing agent to write the routine tests, run the suite, read failures and drive a browser through your main flows, while a person decides what must be covered and checks what each test actually asserts. Good picks are a terminal coding agent, a read-only or test-only subagent and a browser add-on such as Playwright MCP. Model cost per test is cents. Checked 31 October 2026.
The job in one table
Testing task | AI first pass | Human check |
|---|---|---|
Unit tests for existing code | Generates cases, including edge cases | Are assertions meaningful? |
Test gaps | Lists untested branches | Which gaps matter |
Browser flow tests | Drives the app and records steps | Is the flow what users do? |
Reading failures | Summarises logs and likely cause | Is it a bug or a bad test? |
Flaky tests | Suggests causes | Fix versus delete |
Bug reports | Turns a failure into a reproducible report | Severity and owner |
Exploratory testing | Tries odd inputs | Judging usability and feel |
Release decision | Nothing | Always a person |
What the job is
Testing answers one question: does the software do what we meant? It is a good job for agents because the world gives clear feedback. A test passes or fails, and a browser flow reaches a page or does not. Anthropic's guide to building with models notes that agents do well where the environment provides ground truth at each step, such as tool results or code execution. Tests are exactly that signal.
The catch is the one every tester knows. A test can pass and prove nothing. An agent that is told to "make the tests pass" may weaken the assertions until they do. So the human job moves from writing every test to reviewing what the tests claim.
Which agent fits
Your setup | Pick | Why | Page |
|---|---|---|---|
Developers with a terminal workflow | A terminal agent that runs the suite and edits tests | Closes the loop: write, run, read, fix | |
IDE users | An editor agent | Tests next to the code | |
A team wanting a constrained tester | A subagent limited to test files | It cannot touch production code | |
Browser and UI checks | An agent with a browser add-on | Drives the real app | |
Open source, self-hosted | OpenHands or Aider with any model | Run local models for private code | |
A bigger QA programme | A build guide for a QA agent | A repeatable design |
For picking between these tools, see AI coding agents and choose an AI coding agent.
Add-ons and kit items that help
Need | Add-on or kit item | What it gives | Page |
|---|---|---|---|
Drive a real browser | Playwright MCP | Microsoft's Apache-2.0 server; navigates, clicks, reads the page | |
Console, network and performance | Chrome DevTools MCP | DevTools data for debugging | |
A repeatable browser check | Browser QA recipe | Steps to follow and report | |
A test-writing worker | Test writer subagent | Fixed tools and output | |
Failures in production | Sentry MCP | Errors and traces for real cases | |
Library behaviour | Context7 | Current docs, to write correct tests | |
Turn failures into tickets | Linear MCP, Jira MCP, GitHub MCP | Issues with details | |
A bug template | Bug triage prompt | Messy reports into clear ones |
A worked setup that combines the first and third rows is in Claude Code with Playwright for browser QA. Prompts for testing sit in the prompt library. Put your test conventions in a CLAUDE.md or AGENTS.md so every run follows them: where tests live, how to run one, which framework, what never to mock.
A safe workflow, step by step
- Write down what must work. Five user flows and the ten functions that matter most.
- Give the agent the test conventions in an instruction file.
- Generate tests for one module at a time, not the whole repo.
- Run them and read the failures. A failing new test may be a real bug; ask the agent for evidence before you fix anything.
- Mutate to check. Break the code on purpose and confirm a test fails. A test that still passes is not testing.
- Review assertions. Each test should assert a result a user cares about, not just "it did not throw."
- Add browser flows last, against a test environment with test data.
- Run in CI. A test that only runs on the agent's machine does not protect you.
- Keep a human owner of the suite.
Rule 5 is the one to insist on. If you have no time for anything else, break one line of code per generated test file and see if the suite notices.
What a good AI-written test looks like
Compare two tests for the same function, a discount calculator, as an example.
Weak test | Strong test | |
|---|---|---|
Name | "calculates discount" | "applies 10 percent to orders over 100 and none below" |
Setup | Mocks the price service, returns anything | Uses real example prices from the spec |
Assertion | The function returned a number | The result equals 90 for an order of 100 and 99 for an order of 99 |
Edge cases | None | Zero, negative, exactly 100, a very large order |
If the code changes | Still passes | Fails, which is the point |
Ask the agent for the strong kind in your instruction file: "each test asserts a specific expected value taken from the requirements; include boundary cases; do not mock the unit under test." Then run the mutation spot-check: change the threshold from 100 to 101 and confirm a test fails.
Browser flows worth testing first
A small set of flows protects most of the value. Pick the ones where a failure costs you customers or money.
- Sign up and sign in.
- The main thing a user comes to do, from start to finish.
- Checkout or the equivalent paid action, using a test mode.
- Password reset.
- A form that creates a record, then viewing it.
For each flow write the steps and the expected result in plain words first, and let the agent turn that into a script. Run the flow at a phone width as well as on desktop, since layout bugs often show at the narrow size. Keep browser tests few and stable; unit tests are cheaper and faster, and a pyramid with many unit tests and a few browser flows is easier to maintain than the reverse.
Triage: reading a red build
When the suite fails, an agent can save the first twenty minutes. Ask it to answer four questions in order: which tests failed, what changed in the last commit, whether the failure reproduces locally, and whether the cause is in the test or in the code. Require evidence for each answer, such as a log line or a diff hunk. A model that says "probably a race condition" with no evidence has told you nothing. The bug triage prompt gives a layout for turning the answer into a ticket.
What it costs
Model. From Anthropic's pricing page, checked 31 October 2026: Sonnet 5.5 is $2 per million input tokens and $10 per million output; Haiku 5.5 is $0.10 and $0.50.
Worked example (the token counts are our assumptions). Generating tests for one module: 8,000 input tokens (the code and examples) and 3,000 output tokens:
Model | Cost per module | 200 modules |
|---|---|---|
Sonnet 5.5 | $0.016 + $0.03 = about $0.046 | about $9 |
Haiku 5.5 | $0.0008 + $0.0015 = about $0.0023 | about $0.46 |
An agent that also runs the suite, reads failures and retries uses several times that. Browser agents read page snapshots on every step, which costs many more input tokens than code alone. We have no figure for tokens per snapshot, so read your own usage log.
Seats. Terminal agents start at about $20 a month (Claude Code Pro $20, $17 annual; Codex Plus $20; Copilot Pro $10; Cursor Plus $8). See AI coding agent pricing compared. Playwright MCP is free; you pay for the model that drives it. Its README also lists opt-in capability groups you switch on with the --caps option, including --caps=testing for test assertions and --caps=network for request routing, so an agent only gets the extra tools you enable.
People. The review step is the cost that matters. A hundred generated tests at two minutes of review each is over three hours, which is still far less than writing them.
Risks and how to review them
Risk | What it looks like | Control |
|---|---|---|
Weak assertions | Tests that only check no error | Mutation check; review assertions |
Tests that copy bugs | The test locks in wrong behaviour | Derive expected results from the spec, not from the code |
Over-mocking | Everything is mocked, so real failures hide | Require a few real integration tests |
Agent edits the code to pass the tests | Production code changed quietly | A test-only subagent; code-owner review on non-test files |
Flaky browser tests | Pass and fail at random | Waits on conditions, not on time; quarantine and fix |
Destructive browser actions | The agent deletes or buys something | Test environment only, throwaway data, no real payment methods |
Secrets in prompts and logs | Test credentials leak | Use dedicated test accounts and secret storage |
Prompt injection from pages | A page tells the agent to do something | Test your own site only; treat page text as data |
False comfort | A green suite is called "tested" | Report coverage and what is not covered |
Playwright MCP gives an agent control of a real browser, so treat it like handing over your keyboard on that machine. Our add-on page covers its limits and risks. The MCP spec says tools represent arbitrary code execution and hosts should get user consent, and Claude Code's docs say to verify you trust each server.
Measure it
Metric | What it tells you |
|---|---|
Mutation check pass rate on generated tests | Whether tests detect real change |
Real bugs found by AI-written tests | Value |
Flaky rate | Quality of the suite |
Minutes of review per test | Cost |
Escaped defects after release | The result that matters |
Coverage percentage is a weak target: an agent can raise it with tests that assert nothing.
Common mistakes
- Generating tests for the whole repository at once. Review becomes impossible; go module by module.
- Letting the agent change production code to make a test pass. Restrict its edit rights.
- Counting tests, not checking them. Ten strong tests beat a hundred empty ones.
- Testing against production. Use a test environment and throwaway data.
- No CI. Tests that only run when someone remembers do not protect a release.
- Skipping the human. Someone must own the suite, read the failures and decide what to fix.
A first afternoon
Pick one module that changes often and has few tests. Ask the agent to list the behaviours it can see in the code, and compare that list with what you think the module should do. The differences are your first findings. Generate tests for the behaviours you agree on, run them and break one line on purpose to confirm the suite notices. Write down how long it took and how many generated tests you kept. That one afternoon gives you a real number for your own code, which is worth more than any vendor claim.
Who should do what
If you are | Start with |
|---|---|
A solo developer | A test writer subagent on your most-changed module |
A small team | Generated unit tests plus three browser flows in a test environment |
A QA engineer | Use the agent for first drafts and bug reports, keep exploratory work |
A team with CI | A required check that runs the suite and a mutation spot-check |
A regulated product | Human-authored test plans, with AI drafting cases for review and an audit trail |
Related tasks: AI code review for the review of the change itself, AI documentation for keeping docs true to the tests and AI tools for business for choosing across jobs.
Our take
Testing suits agents because tests give honest feedback, and it fails when nobody checks what the tests mean. Constrain the agent to test files, insist on a quick mutation check and keep a person on the release call. We built this from vendor documentation, our add-on pages and published guidance, and have not run these agents on a production suite ourselves, so pilot on one module before you trust the pattern.
Questions
What can an AI testing agent do?
Write unit and integration tests for existing code, drive a real browser through key user flows, run the suite and read failures, and propose fixes. A person must check that the tests assert something meaningful.
Can AI replace QA?
No. It speeds up routine test writing and exploration. People still decide what must be tested, judge usability and own release decisions.
What is the main risk with AI-written tests?
Tests that pass but prove little: weak assertions, tests that copy the current behaviour including its bugs, or mocks that hide real failures.
What does it cost?
The model cost per generated test is cents. Browser agents use more tokens because they read page snapshots. Seats for terminal agents start around $20 a month.
Loading poll...