We asked an AI tool to write tests for an expense claim page. This was the whole request.
Write Playwright tests in TypeScript for the expense claim page at http://localhost:4308. The app is running. Save the tests in tests/claims.spec.ts.
The tool opened the page, tried it, and wrote 27 tests. It ran them, and all 27 passed. It ran them a second time to be sure.
The page had a bug. The company's finance policy says one claim can be at most 500.00. This copy of the app accepted claims up to 1000.00. We had put that bug there on purpose. We call that a planted bug.
No test failed, because one of the 27 tests now says the bug is correct. This lecture is about how that happened, and what you have to bring so that it does not.
Claim Desk is a small expense claim app that we built for this course. It is not online, so the code here is for reading. The examples in this course are Playwright tests, because that is what we asked the tools for. Your exercises run in the framework you chose.
The test that protects the bug
This is one test from that file, unchanged, with the import line from the top of the file. claimsUi and submitClaim are helpers the tool wrote further up. claimsUi finds the parts of the page. submitClaim fills the form and clicks Submit claim.
import { test, expect, type Page, type Locator } from '@playwright/test';
test('accepts exactly 1000.00, the employee limit', async ({ page }) => {
const ui = claimsUi(page);
await submitClaim(page, { amount: '1000.00', receipt: 'R-1' });
await expect(ui.status).toHaveText('Claim saved');
await expect(ui.error).toBeEmpty();
await expect(ui.rows.first().getByRole('cell').nth(1)).toHaveText('1000.00');
await expect(ui.pendingTotal).toHaveText('1138.50');
});
Line by line:
submitClaimsends a claim of 1000.00 with a receipt number.- The next two checks expect the message "Claim saved" and no error.
- The last two checks expect the new claim at the top of the list, and the pending total to rise from 138.50 to 1138.50.
So every check says the same thing: a claim of 1000.00 is saved.
Look at the title. Nobody told the tool about an "employee limit" of 1000.00. It tried amounts, saw that 1000.00 was saved and 1000.01 was refused, and gave what it saw a name.
Two more tests expect 1000.01 and 5000 to be refused with the message "Claims above 1000.00 must be submitted by your manager." That message is what this copy of the app shows.
So the tests are a correct description of a wrong app. When a developer later fixes the limit to 500.00, three of these tests fail. We checked that by running the file on the correct app. The tests would then report the fix as a problem.
Why the tool could not know
The tool had the page and nothing else. From the page it can learn what the app does. It cannot learn what the app should do.
Those are two different facts, and they come from different places.
- What the app does is in the app. Anyone can find it by trying inputs, and a tool does this fast.
- What the app should do is a decision somebody made. It is in a policy, a ticket, a design or a person's head. A ticket is the written task for a piece of work, kept in the team's tracker.
When the app is correct, the two facts are the same, and tests written from the app look perfect. A tester is paid for the cases where they differ.
The same request, with the rule
We sent the request again, to a fresh session of the same tool. This time it ended with two more sentences and a feature note.
Test the rules in this feature note. Take every expected result from the note. If a rule cannot be tested from the page, say so and do not guess.
A feature note is a short document that you write before you test. It lists each rule and where the rule comes from. This is the note we attached. Lecture 2 shows how to build one.
Feature note: expense claims in Claim Desk (ticket CD-214)
Rules, each with its source:
1. The amount is a number greater than 0, with at most two decimals. Otherwise the page says "Enter an amount greater than 0." Source: finance policy 3.1.
2. One claim can be at most 500.00. A claim of exactly 500.00 is allowed. Above that, the page says "Claims above 500.00 must be submitted by your manager." Source: finance policy 3.2, confirmed by the product manager in the ticket.
3. A claim of 50.00 or more needs a receipt number. Below 50.00 the receipt number is optional. Without it, the page says "Add a receipt number for claims of 50.00 or more." Source: finance policy 3.4.
4. A saved claim appears at the top of "Your claims" with a new claim number, the category that was chosen and the status Pending. "Pending total" rises by the amount. Source: ticket CD-214.
5. Withdraw opens a dialog that names the claim and its amount. "Keep claim" changes nothing. "Withdraw claim" sets that claim, and no other, to Withdrawn. The claim stays in the list. "Pending total" falls by its amount. Source: ticket CD-214. The product manager confirmed that withdrawn claims do not count in the total.
Observed on the page, not confirmed by anyone:
- Saving takes up to about one second. The page shows "Saving..." and then "Claim saved".
- The page opens with three claims: C-1003 Equipment 240.00 Approved, C-1002 Meals 18.50 Pending, C-1001 Travel 120.00 Pending. The pending total is 138.50.
- An approved claim has no Withdraw button.
Open questions, not answered yet:
- Is a duplicate claim allowed?
- What happens to the form after a refused claim?
The reply had 20 tests. When the tool ran them, 18 passed and 2 failed. It did not change the two failing tests. It wrote this:
"500.01 and 750.00 are both saved as Pending, and no message appears."
"So the server's limit is 1000.00, while the note (finance policy 3.2, confirmed by the product manager) says 500.00."
"Whether the fix belongs in the app or the note is a decision for the product manager or finance."
That is a bug report. The same tool, on the same app, went from protecting the bug to finding it. The only thing that changed was that the request carried the rule and its source.
A second tool, Codex, got both requests too. With the short request it wrote five tests, and none of them tried the limit. With the note it wrote ten, and one of them failed on this copy of the app: "rejects an amount above 500.00 (finance policy 3.2)".
The bug the tool found alone
It would be unfair to stop here. On another copy of the app, the short request was enough.
That copy had a different planted bug. The policy says a claim of 50.00 or more needs a receipt number. The copy asked for a receipt only above 50.00. So a claim of exactly 50.00 was saved without one.
The short request, with no note, produced 35 tests. One failed, and the tool reported it:
"The error says 'Add a receipt number for claims of 50.00 or more.' But the server accepts a claim of exactly 50.00 with no receipt."
Here the app disagreed with itself. Its own message stated the rule, and its behaviour broke it. The tool found the rule on the page and checked the page against it.
So this is the line between the two cases.
- If the app disagrees with itself, a tool that can try the app may find the bug alone.
- If the app agrees with itself and is still wrong, the tool has nothing to compare it with. The wrong limit of 1000.00 was in the check and in the message. Everything on the page matched.
We planted the 1000.00 bug so that the page would agree with itself. You should know that when you judge this result. But the same thing happens on real projects. A developer reads the policy wrong once, and then writes the check, the message and the unit tests from that one reading.
What only you can bring
The tool brought speed. It also brought more input ideas than most people write in an hour: empty amounts, text, three decimals, spaces. It could not bring three things.
- The rule. What the feature should do, in a sentence that can be checked.
- The source. Where the rule comes from, so that a disagreement can be settled.
- What is only observed. The things you saw on the page that nobody has confirmed.
Finding those three things is testing work. It happens before any tool is opened, and the first half of this course is about it.
What this course covers
- Lectures 1 to 4 are about the work before automation: understanding the feature, and writing or checking test cases with a tool.
- Lectures 5 to 8 are about working with a tool that can change files: what to give it, how to read its plan and its changes, and how to show that a test can fail.
- Lectures 9 to 12 are about failing tests, cost, the choice of tool, and what stays your responsibility.
Each lecture ends with an exercise on this site. You may write the test with any AI tool or without one. We run it on the working app and on copies with a planted bug, and we tell you which bug it missed.
Our other course, Review Tests Written by AI, is about checking a test after a tool wrote it. This course is about the work around that.
How these runs were made
Every AI example in this course is a real run. We wrote each request, sent it once, and kept the reply and the files unchanged. Then we ran the tests ourselves on the correct app and on copies with one planted bug each.
- The tools. Claude Code 2.1.336 with its default model, which it reported as
claude-opus-5-5. Codex CLI 0.162.1 with its default settings, which it reported as the modelgpt-6.1-terrawith reasoning effort "none". Lecture 11 explains what a model and a reasoning effort are. - The date. 5 December 2026.
- The access. Each tool worked in a folder with a test setup and could reach the running app. Unless a lecture says so, it could not see the app's server code.
- One limit on Codex. Codex runs commands inside a sandbox, a restricted area that protects your computer. We allowed its sandbox to use the network, so that it could reach the app. Inside the sandbox it still could not start the Chrome browser. So it wrote tests and could not run them, and it said so in its replies. We ran its tests ourselves.
We ran both tools ourselves, and Claude Code is also the tool we use to build this site. So this is not independent evidence. Each request was sent once, to one small app. These runs do not show how AI tools behave in general.
What we expected and did not see
We expected to show you some well-known faults. We did not find them.
- A weakened test. In lectures 7 and 9 we gave the tools a failing test and asked them to make it pass. No tool removed a check or changed an expected value.
- A fixed wait. A fixed wait pauses the test for a set time. No tool added one in any run. In lecture 9, both tools removed one.
- An invented number. In lecture 2 we gave the tools a ticket with no numbers in it. Neither tool invented the numbers.
The faults we did find were less obvious, and each one has a lecture: tests that describe a wrong app, a bug that seven test files missed in the same way, tests that were never run, and a change to the app that nobody asked for.
Your exercise. A shop cart must show the price times the quantity. The exercise gives you the rule and the numbers. Write the test with or without an AI tool. Take the expected subtotal from the rule in the exercise, not from what the cart shows.
Remember this:
- A tool that has only the app can tell you what the app does. It cannot tell you what the app should do.
- Tests written from a wrong app pass, and then they protect the mistake.
- Give the tool the rule and its source. With them, the same tool reported the bug.
- A tool can find a bug alone when the app disagrees with itself. It cannot when the app agrees with itself.
Reference: Best practices.