How to Tell If the AI's Tests Actually Test Anything

To tell whether a test checks anything, break the code on purpose and see if the test fails. A test that stays green through every break you try is decoration. Do it for each test and you get a table that shows which ones to trust. The engineers’ name for this is mutation testing, and the hand-made version below needs no tools.
This is for you if the AI wrote your tests and you have never seen them fail. In one scratch run on a ten-line function, 5 of 9 tests never failed once, and a linter (a spell-checker for code) caught only 2 of those 5.
The function and the nine tests
A discount function, the kind an AI writes without thinking about it:
export function applyDiscount(price, percent) { if (percent < 0 || percent > 100) throw new Error('bad percent'); return Math.round(price * (100 - percent)) / 100;}The rules in plain English: 10% off $100 is $90, 100% off is free, a discount below 0% or above 100% is rejected, and the result is rounded to cents.
The suite has nine tests, A to I. Five are shapes that AI-written tests drift toward, and they were written here to show the patterns. Four check real rules:
import { it, expect } from 'vitest';import { applyDiscount } from './price.js';
it('A no assertion at all', () => { applyDiscount(100, 10);});it('B matcher never called', () => { expect(applyDiscount(100, 10)).toBe;});it('C only checks it exists', () => { expect(applyDiscount(100, 10)).toBeDefined();});it('D try/catch swallows the failure', () => { try { expect(applyDiscount(100, 10)).toBe(12345); } catch (e) {}});it('E asserts a constant', () => { expect(true).toBe(true);});it('F 10% off $100 is $90', () => { expect(applyDiscount(100, 10)).toBe(90);});it('G 100% off is free, 0% off changes nothing', () => { expect(applyDiscount(100, 100)).toBe(0); expect(applyDiscount(100, 0)).toBe(100);});it('H more than 100% off is rejected', () => { expect(() => applyDiscount(100, 101)).toThrow();});it('I result is rounded to cents: 10% off $19.95 is $17.96', () => { expect(applyDiscount(19.95, 10)).toBe(17.96);});To follow along you need Node installed. In an empty folder run npm init -y, npm pkg set type=module scripts.test="vitest run" and npm i -D vitest, save the two files as price.js and suite.test.js, and run npm test. All nine pass. No terminal? Skip ahead to the prompt near the end and have your AI run the audit on your own project.
Which tests notice a break?
Break price.js six ways, one edit at a time, and run the suite after each (commit first so you can undo). Here is the table from the scratch run. X means the test failed, a dot means it stayed green:
A B C D E F G H Ioriginal: . . . . . . . . .drop lower bound: . . . . . . . . .drop upper bound: . . . . . . . X .wrong constant: . . . . . X X . Xfloor, not round: . . . . . . . . Xlimit off by one: . . . . . . X . .swap price, percent: . . . . . X X . XLegend: A no assertion, B matcher never called, C only checks existence, D try/catch, E constant, F 10% off $100, G the 0% and 100% cases, H over 100% rejected, I rounding to cents.
Read it by columns. A, B, C, D and E are never marked. The function can drop a check, use the wrong constant or return the wrong number, and those tests stay green. They are decoration. (Test A can still fail if the code crashes, which is all it proves.)
Now read it by rows, because this is the better trick. Two rows are interesting. “Drop lower bound” has no X at all: removing the check for a negative discount is invisible to every test, because H only tries 101. A break that nobody notices is a rule nobody tests. Add the missing test:
it('J a negative discount is rejected with a clear message', () => { expect(() => applyDiscount(100, -5)).toThrow('bad percent');});Re-run the same six breaks and J is the test that fails on “drop lower bound”. The lesson: one break per rule, not one break per function. A first attempt used a single “remove the validation” break that deleted both checks at once, and it hid this gap.
The second row is “floor, not round”. A first draft of test I used $19.99 and the row was empty, because 19.99 at 10% off lands on a whole cent either way. Changing the example to $19.95 made test I catch it. A test with the right name and the wrong example is decoration too.
Why do these five tests never fail?
- A, no assertion. Nothing to fail, unless the code crashes.
- B, matcher never called.
.toBewithout parentheses and an argument is a property read, not a check. Vitest ran it green. - C, only checks it exists.
toBeDefined()passes for any value, including a wrong one. - D, try/catch around the expect. The failed assertion throws, the catch swallows it, and the test passes.
- E, a constant.
expect(true).toBe(true)can never fail, whatever the code does.
Two more ways to a false green. The first was run in a separate scratch project: a snapshot test (toMatchSnapshot()) writes its expected value on the first run, so it passes whatever the code returns, and after a break vitest run -u rewrites the snapshot to the wrong value and goes green again. The second was not run, but it is the same trick by hand: someone, human or AI, edits the expected value in a test until it matches the output. That is why every audit should end with git diff --stat on the test files. Clean output means no test file shows up unless you asked for a change.
Can a tool find them for me?
Partly. Installing @vitest/eslint-plugin (1.6.28 with ESLint 10 in the scratch run; it replaces the older eslint-plugin-vitest name) and turning on its expect-expect, valid-expect, no-conditional-expect, no-disabled-tests and no-focused-tests rules gave:
suite.test.js 4:1 error Test has no assertions vitest/expect-expect 8:34 error Matchers must be called to assert vitest/valid-expectIt caught A and B. It did not catch C, D or E, because each has an assertion that is fine in shape and empty in meaning. A linter reads the shape of a test, not whether the test could ever fail. Turn it on, but do not read a clean lint run as proof.
Two more things that do not save you. Coverage counts code that ran, not code that was checked: the three weak tests in tests for people who do not write code scored 100% of lines in that post’s run. And skipped tests do not fail a run: it.only skips every other test in its file and the summary reads 1 passed | 2 skipped with a green exit. The lint rules flag both.
How do I run this on my own tests?
Three passes, a few minutes each:
- Lint. Add the lint plugin for your test runner and fix what it flags.
- Read the names. Each should contain a rule and an example number. Rewrite or delete the ones that say “works” or “returns a value”.
- Break it on purpose. For each shared function, make one-line breaks, one per rule, run the suite after each, and note which tests fail. Any test that never fails, and any break nobody notices, goes on your fix list.
The tool version of pass 3 is mutation testing with Stryker, which found the missing lower-bound test in two seconds. It does not try every break a human would think of (in the scratch run it never swapped Math.round for Math.floor), so the hand-made table and the tool complement each other.
You can ask your AI to do pass 3, if you tell it to show its work:
Audit these tests without changing any test. For each test, state the rule it is supposed to protect. Then for each function under test, make one-line breaks to the real code, one per rule, one at a time: change a constant, flip a comparison, remove one validation, return a constant, change a rounding call. After each break, run the tests and record which tests failed, then undo the break before the next one. Show me a table with tests as columns and breaks as rows. List every test that never failed and every break that no test caught. Do not fix anything yet.
Then check it was real: ask for the raw output of one run, and run git diff --stat to confirm no source file was left broken.
The one check an engineer does by hand
Pick the single function whose failure would cost you money, break it on purpose, one rule at a time, and run the tests. If they stay green, you do not have tests for it, whatever the file count says.
For what to ask for in the first place, see tests for people who do not write code and TDD with an AI. For tests that catch the second screen a fix breaks, see test behaviors, not code.
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.