Tests for People Who Do Not Write Code: Ask the AI for These

· 9 min read ·
vibe-coding testing debugging ai

A man in a green sweater proudly holds a clipboard full of green checkmarks while a small white robot in a detective hat snips a wire on a toy machine behind him, and the machine's green lights stay on

Ask the AI for tests that check the rules your app must never break: what things cost, who can see what, the one thing your app exists to do, and anything that deletes data. Write those rules in plain English first, and then check the tests by breaking one line on purpose. If every test stays green, the tests are decoration.

You do not need to read test code to do this. You need to read sentences and watch a color change.

Why do AI-written tests always pass, and can green mean nothing?

Because of the order they were written in. When the AI writes tests after the code, it reads the code and writes tests that agree with it. If the code has a bug, the tests often agree with the bug.

That is not a hunch. A University of Waterloo study (published in IEEE Software) fed LLM-based test generators real buggy student code, and the tools could miss the bug or keep tests that validated it. Caveat: small Python functions and two tools, not a full Lovable or Cursor app. The mechanism is still the one you will meet: the code is the AI’s only source of truth, so it treats the code as correct. A one-page spec your AI can follow gives the tests something else to agree with.

Your tool may already be writing tests. Lovable’s docs say it adds a small test when you add or change a rule (a price, a limit, a permission, a date, who can do what). That is a sensible default. You still have to know whether those tests would ever fail.

What does a test that tests nothing look like?

Here is a ten-line checkout, small enough to read. The business rules, in plain English:

  • The coupon SAVE10 takes 10% off.
  • Shipping is $5.00, free once the order is $50.00 or more after the coupon.
  • Money is counted in whole cents (5000 is $50.00), so totals are exact.

The code the AI wrote:

export function orderTotal({ subtotalCents, coupon }) {
const discount = coupon === 'SAVE10' ? Math.round(subtotalCents * 0.1) : 0;
const shipping = subtotalCents >= 5000 ? 0 : 500;
return subtotalCents - discount + shipping;
}

There is a bug in it. Look at the shipping line. It checks the subtotal before the coupon. A $55.00 cart with SAVE10 is really $49.50 of items, so the customer owes $5.00 shipping, and this code charges nothing for it. You are giving away shipping, quietly, on every order near the line.

Now three tests of the kind you get when an AI reads that code and is told to “add tests”. They were written here to show the failure, then run with Vitest 5.1.2 on Node 22:

it('returns a number', () => {
expect(typeof orderTotal({ subtotalCents: 10000, coupon: 'SAVE10' })).toBe('number');
});
it('applies the coupon', () => {
expect(orderTotal({ subtotalCents: 10000, coupon: 'SAVE10' })).toBe(9000);
});
it('works with the mocked function', () => {
const fake = vi.fn().mockReturnValue(9000);
expect(fake({ subtotalCents: 10000, coupon: 'SAVE10' })).toBe(9000);
});

Result: 3 passed. A clean green run, and a bug in production.

Two of those three tests could never fail. The first only checks that the answer is a number. The third is the worst kind: it builds a pretend version of the function, tells the pretend version to answer 9000, and then checks that it answered 9000. The real code is never called.

How do I check tests without reading them?

Sabotage the code and watch. In the scratch run 0.1 was changed to 0.5 (a 50% coupon, a very expensive typo) and the same three tests were run again:

Test Files 1 failed (1)
Tests 1 failed | 2 passed (3)

One test noticed, the single honest one. The other two stayed green with the coupon broken. And none of the three catches the shipping bug, because no test was written from the rule.

One more trap if your tool shows a coverage number. The three weak tests were run with Vitest’s coverage report (@vitest/coverage-v8): 100% of lines, 50% of branches. Coverage counts lines that ran, not lines that were checked. A test that calls your code and asserts nothing useful still earns the percentage. Branches told the truth here, because only one side of the coupon check ever ran.

This sabotage check is a hand-made version of what engineers call mutation testing. To run it across a whole suite and read the results as a table, see how to tell if the AI’s tests test anything.

Now the same code against tests written from the plain-English rules:

it('shipping is decided AFTER the coupon: $55.00 with SAVE10 is $49.50 of items, so it pays $5.00 shipping', () => {
expect(orderTotal({ subtotalCents: 5500, coupon: 'SAVE10' })).toBe(5450);
});
FAIL shipping is decided AFTER the coupon: $55.00 with SAVE10 ...
AssertionError: expected 4950 to be 5450

Red, with a sentence that tells you what is wrong. That is what a test is for.

Fix the shipping line so it uses the price after the coupon, and run it again:

export function orderTotal({ subtotalCents, coupon }) {
const discount = coupon === 'SAVE10' ? Math.round(subtotalCents * 0.1) : 0;
const items = subtotalCents - discount;
const shipping = items >= 5000 ? 0 : 500;
return items + shipping;
}
Tests 4 passed (4)

You can reproduce the whole thing in a scratch folder in two minutes. Save the buggy function above as cart.js, the four rule tests below as rules.test.js, then run:

Terminal window
npm init -y
npm pkg set type=module scripts.test="vitest run"
npm i -D vitest
npm test
import { it, expect } from 'vitest';
import { orderTotal } from './cart.js';
it('SAVE10 takes 10% off the items', () => {
expect(orderTotal({ subtotalCents: 10000, coupon: 'SAVE10' })).toBe(9000);
});
it('shipping is $5.00 under $50.00 and free at $50.00 or more', () => {
expect(orderTotal({ subtotalCents: 4900, coupon: '' })).toBe(5400);
expect(orderTotal({ subtotalCents: 5000, coupon: '' })).toBe(5000);
});
it('shipping is decided AFTER the coupon: $55.00 with SAVE10 pays $5.00 shipping', () => {
expect(orderTotal({ subtotalCents: 5500, coupon: 'SAVE10' })).toBe(5450);
});
it('an unknown coupon changes nothing', () => {
expect(orderTotal({ subtotalCents: 2000, coupon: 'NOPE' })).toBe(2500);
});

Three of four pass and one fails against the buggy file. Swap in the fixed cart.js and all four pass. This was run exactly as shown in a fresh folder.

What do I ask the AI for?

Do it in four steps. The order matters more than the wording.

  1. Rules first, no code. Ask for your description as a numbered list of plain-English rules, each with a concrete number. Read the list. You are the only one who knows what the app should do, so this is where you catch a wrong rule.
  2. Tests from the list only. One test per rule, named as a sentence, checking what a user would see (the total, the shipping, the error), not how the code works inside (runnable example). No mocks of your own code.
  3. Show it failing. On existing code, a red test is a bug found. For new work, the test-first post runs the loop end to end, and Anthropic’s Claude Code guide says the same: confirm the new tests fail, then write the code, and do not let the AI edit the tests.
  4. Sabotage once, and you pick the rule. Choose a rule from your plain-English list (“make the coupon 50%”, “remove the shipping check”) and ask the AI to break the code that implements it, run the tests, show you which went red, then undo it. If the AI picks the line, it will tend to pick one its tests already cover. A tool called Stryker (npx stryker run, for JavaScript and TypeScript) automates this across a whole project: mutation testing in plain English.

A prompt you can paste:

Before writing any test, read my description of how this feature should work and turn it into a numbered list of rules in plain English, each with a concrete example number (for instance “a $55 order with SAVE10 pays $5 shipping”). Show me the list and wait for my approval. Then write one test per rule from that list only. Name each test as a full sentence. Do not mock any function from this project and do not check types or “returns something”. Run the tests once (not in watch mode) and show me the result. Then wait: I will name one rule, and you will break the code that implements it, run the tests, show me which turned red, and undo the change. Never edit a test to make it pass: if a test fails, tell me and ask.

Which rules go first?

Start with rules where a failure costs money or trust:

Rule typeExample in plain English
MoneyA $55.00 order with SAVE10 pays $5.00 shipping.
Who can see whatUser A cannot open user B’s invoice by changing the id.
The one thing the app exists forA paid user can generate a report and a free user hits the limit on the third.
Who can do whatA free user’s third report is refused; a paid user’s is not.
Anything that deletesDeleting a project asks for confirmation first.
The edges$49.00 pays shipping, $50.00 does not.

Ask for the edges by name: AI-written tests love the comfortable middle and skip the boundary, where off-by-one bugs live.

Gotchas an engineer would warn you about

  • “Tests pass” and “the AI edited the tests” look identical in chat. After any fix, run git diff --stat and see whether a file with test in its name changed. If it did, the AI may have changed the question instead of fixing the answer. No terminal? Ask the AI to list every test file it touched and what changed. More in Your AI Fixed One Bug and Broke Two.
  • Ask for the raw output. “All tests pass” in chat is a claim; the pasted test results are evidence.
  • Watch mode waits for you. Hosted tools such as Lovable run tests themselves, so this is for Cursor and Claude Code users. In your own terminal, vitest on its own stays open and reruns on every change; Vitest’s CLI docs say it runs once in CI or a non-interactive shell. vitest run removes the doubt. Vitest’s guide lists the current requirement: Vite 6.4+ and Node 22.12+.
  • Rules that live only in chat are lost. Keep your plain-English list in a file in the project, so the next session starts from it instead of from the code.
  • Some things are not worth unit tests. Copy, colors and layout belong to your eyes. For a whole flow like checkout, ask for a browser test: Lovable calls this browser testing, and Cursor or Claude Code can use Playwright.

The one check an engineer does by hand

Read only the test names. Each one should be a sentence that contains a rule and a number. If you see “works correctly”, “handles input” or “should return a value”, you are looking at tests that were written to pass. Then do the sabotage run. It takes three minutes.

The launch checklist lists what else to confirm before real users arrive, and what breaks when a vibe-coded app gets real users explains why tests that rerun after every change are the first thing to buy.

The Get AI Native ebook goes deeper on this. It is free, and the expected launch is around Christmas. Join the waitlist on the homepage.

Comments