# Why AI-written tests pass when they shouldn’t

Source: https://testwatch.dev/blog/ai-written-tests-always-pass
Updated: 2026-11-04

The quickest way to make a failing test pass is to make it check less. The seven rewrites that do it, the reason our check returns for each, the ones it lets through, and what to ask of any AI-written test diff.

By [Vasyl Harastei](https://testwatch.dev/about). 4 November 2026. 8-minute read.

Ask an AI model to make a failing test pass, and it will. The quickest way is to make the test check less. A test that went red because the cart held one item instead of two turns green, and the cart is still wrong. That is one of the main ways an AI-written test ends up passing on a broken app: a **false green**.

TestWatch writes Playwright tests with an AI agent. When a new test fails its first runs, the agent usually gets one try to repair it. So we built a check that compares the repair with the original and names the ways the rewrite checks less. Below are the seven kinds it knows, the rewrites it lets through, and what to ask of any AI-written test diff. Every example on this page goes through the real checks each time we test the site.

## Where tests that always pass come from

**It checks that something happened, not what.** The request was “place an order and check the total”; the test checks that the confirmation page loaded. That page loads with any total.

**Its expected value came from a broken screen.** If the app already shows the wrong total while the test is being written, a model that copies what it sees writes the wrong total into the test. The test then passes because the bug is there.

**A failing check was rewritten until it passed.** The test was right, the app was wrong, and the fix changed the test. This is the one you can catch from the code alone, because you have both versions: the check that failed and the check that replaced it.

## Seven ways a rewrite checks less

Each example starts from a check that failed and shows a rewrite of it; all but the last turn the run green. Most use the same check, a cart line that must read “Canvas tote × 2”, so you can compare them. The line under each one is what our check returns for the pair, word for word.

### Deleting the check

The simplest fix: remove the line that failed. The cart heading still appears, so the test passes whatever the cart holds.

The original check

```
await expect(page.getByRole('heading', { name: 'Your cart' })).toBeVisible();
await expect(page.getByTestId('cart-line')).toHaveText('Canvas tote × 2');
```

The rewrite

```
await expect(page.getByRole('heading', { name: 'Your cart' })).toBeVisible();
```

What the check returns

removed:expect(page.getByTestId('cart-line')).toHaveText('Canvas tote × 2')

### A value turned into a presence check

In [Playwright’s words](https://playwright.dev/docs/api/class-locatorassertions), `toBeVisible()` “Ensures that Locator points to an attached and visible DOM node.” It passes for any cart line at all, one tote or ten.

The original check

```
await expect(page.getByTestId('cart-line')).toHaveText('Canvas tote × 2');
```

The rewrite

```
await expect(page.getByTestId('cart-line')).toBeVisible();
```

What the check returns

specific_to_presence:toHaveText->toBeVisible

### An exact text turned into a contains

[Playwright’s docs](https://playwright.dev/docs/api/class-locatorassertions) describe `toHaveText` as “Ensures the Locator points to an element with the given text.” and `toContainText` as “Ensures the Locator points to an element that contains the given text.” “Canvas tote × 1” contains “Canvas tote” too.

The original check

```
await expect(page.getByTestId('cart-line')).toHaveText('Canvas tote × 2');
```

The rewrite

```
await expect(page.getByTestId('cart-line')).toContainText('Canvas tote');
```

What the check returns

text_to_contains:toHaveText->toContainText

### An exact text turned into a pattern

The pattern accepts any quantity. A cart with one tote matches it.

The original check

```
await expect(page.getByTestId('cart-line')).toHaveText('Canvas tote × 2');
```

The rewrite

```
await expect(page.getByTestId('cart-line')).toHaveText(/Canvas tote × \d+/);
```

What the check returns

literal_to_pattern:toHaveText

### An exact count turned into “not zero”

In [Playwright’s words](https://playwright.dev/docs/api/class-locatorassertions), `toHaveCount` “Ensures the Locator resolves to an exact number of DOM nodes.” Two different products went into the cart, so it shows two rows; the rewrite passes with one row, or five.

The original check

```
await expect(page.getByTestId('cart-row')).toHaveCount(2);
```

The rewrite

```
await expect(page.getByTestId('cart-row')).not.toHaveCount(0);
```

What the check returns

count_to_nonzero:toHaveCount(2)->not.toHaveCount(0)

### A check turned around

The original said the cart counter must not read 0 after adding an item. The rewrite expects 0, which describes the bug as the correct behaviour.

The original check

```
await expect(page.getByTestId('cart-count')).not.toHaveText('0');
```

The rewrite

```
await expect(page.getByTestId('cart-count')).toHaveText('0');
```

What the check returns

negation_flip:toHaveText

### A check made soft

This one doesn’t turn the run green on its own: Playwright’s docs say [failed soft assertions do not terminate test execution, but mark the test as failed](https://playwright.dev/docs/test-assertions). The check counts it anyway. A repair that changes how a check fails, not why, has fixed nothing.

The original check

```
await expect(page.getByTestId('cart-line')).toHaveText('Canvas tote × 2');
```

The rewrite

```
await expect.soft(page.getByTestId('cart-line')).toHaveText('Canvas tote × 2');
```

What the check returns

hard_to_soft

**The looser shapes aren’t wrong on their own.** A pattern, a contains, a presence or a “not zero” check is the right way to assert a value that changes every run. TestWatch’s own instructions tell the agent to check only the shape of order numbers, dates and prices. What the loosening check judges is the change: an exact check that failed, rewritten looser until it passed. When the request says what a value must be, a shape check isn’t enough, and our eval below shows what the shape rule costs there.

## What the check lets through

The check leaves these rewrites alone on purpose.

**A different expected value.** The text may really have changed: a renamed product, a new quantity rule. Or the app may be wrong and the rewrite copied the wrong value. The code looks the same either way, so the check doesn’t count it as loosening.

The original check

```
await expect(page.getByTestId('cart-line')).toHaveText('Canvas tote × 2');
```

The rewrite

```
await expect(page.getByTestId('cart-line')).toHaveText('Canvas tote × 1');
```

What the check returns: nothing, it lets this through

**The same check on another element.** If the line moved to a different element, checking the same text there is as strict as before.

The original check

```
await expect(page.getByTestId('cart-line')).toHaveText('Canvas tote × 2');
```

The rewrite

```
await expect(page.getByTestId('cart-summary')).toHaveText('Canvas tote × 2');
```

What the check returns: nothing, it lets this through

## What TestWatch does with a loosened repair

Before a generated test is accepted, it runs more than once. If it fails on a bot check, a one-time code it can’t enter, or an app that can’t be reached, there is no repair: a rewrite can’t fix any of those. Otherwise a separate check first asks whether the app is at fault. When it is confident and a second one confirms it, there is no repair either, because a repair would only rewrite the test around the bug. In every other case the agent gets one repair, with the failing test and its error.

When the error is a wrong value, the repair instructions say not to loosen the check and to report an app bug when the app’s value contradicts the request. If the original failed every run on a wrong value or a wrong URL, a repair that goes green by loosening the check that failed is thrown away. TestWatch keeps the original test, doesn’t mark it ready, and tells you the failure looks like a bug in the app.

Two other rewrites can happen during generation: adding checks the test is missing (next section), and fixing a test that passed on one device but failed on another of the same screen size. Neither is used if it loosens any check the test already had.

## Does the test check what you asked for?

A test that was never strict can’t be loosened. So a separate AI check, the goal check, reads the request and the finished, passing test and lists each outcome the request asks for that no assertion verifies. When it is fairly sure there are gaps, or isn’t sure about one, and no repair has run yet, the agent gets one more try to add the missing checks. That version is used only if it still passes every run, checks more, and loosens nothing. If gaps remain, the test usually still ships, marked ready, with a note naming each outcome it doesn’t check. Only a test the goal check is very sure is weak, after a repair or after a try to add checks that wasn’t used, is held back as not ready.

## After a deploy, fixes don’t touch checks

When a test that used to pass breaks, TestWatch may propose a fix. Fixes to your main tests change only locators and waits, never assertions, and apply only after you approve them. That rule is stricter than the loosening check: even a new expected value is refused.

There is one exception. On a pull-request preview (Starter or higher), a fix may also update the text a check expects or looks for when the PR renamed it. It runs on that PR only after someone accepts it, and it is applied to the main test automatically once it passes twice against your main app, with a notice and an Undo. It may change only the text: the matcher stays, a check with `.not` can’t change at all, text can’t become a pattern, nothing can be removed, and the new text can’t be blank or cut to fewer than three characters. Here is one renamed heading, judged both ways:

The check before the PR

```
await expect(page.getByRole('heading', { name: 'Register' })).toBeVisible();
```

A fix that follows the rename

```
await expect(page.getByRole('heading', { name: 'Sign up' })).toBeVisible();
```

A fix that drops the name instead

```
await expect(page.getByRole('heading')).toBeVisible();
```

| The fix | On a main test | On a PR preview |
| --- | --- | --- |
| Follows the rename | Refused | Allowed, after someone accepts it |
| Drops the name | Refused | Refused |

## Questions to ask of an AI-written test diff

The same checks work by eye on any AI-written test diff. For every changed `expect` line, ask:

1. Did an `expect` line disappear?
2. Did a value check become `toBeVisible()` or another presence check?
3. Did `toHaveText` become `toContainText`?
4. Did a quoted value become a pattern?
5. Did an exact count become “not zero” or “greater than”?
6. Did a `.not` appear or disappear?
7. Did `expect` become `expect.soft`?

A yes isn’t always wrong: for a value that really changes between runs, like an order number, a looser check is the fix. It is wrong when the request says what the value must be. If an expected value changed, ask one more: where did the new value come from? From the request or a deliberate product change, or from what the screen showed when the test failed? Only the first is a fix.

If an AI coding assistant edits your tests, you can give it the same rule in its instructions file:

```
When a test fails, find out why before changing it.
Never make a failing check pass by checking less:
- no deleted expect
- no exact text turned into toContainText or a pattern
- no value check turned into toBeVisible
- no exact count turned into "not zero"
- no added or removed .not
- no expect turned into expect.soft
The one exception: a value that really changes between runs (an order number, a date) and
that the request does not fix. Then check its shape, and say why in the change.
If the app shows a value the request says is wrong, report it as a bug.
Change an expected value only when you know the new one is right (the request says so, or
the product changed on purpose), never because the screen showed it when the test failed.
```

## What our eval saw

Our eval plants bugs in fixture apps and counts a test that passed when it should have failed as a false green. In the run on 18 October 2026, 1 of 87 trials was a false green (1%). It came from “Check the order total while it is wrong”. In that trial the app showed a wrong total, and the request asked for a total equal to the sum of the two items. The test checked only that the total looked like a price, and that it was above zero, which follows our own shape rule for prices. The goal check flagged that the sum was never checked, but it wasn’t sure enough to hold the test back, so the test shipped ready, with a note. The agent got one try to add the missing check, but it produced no new test, so the first version shipped and the loosening check had nothing to compare: the test was weak from its first version. The cases, the planted bugs and every trial are on [How we measure TestWatch](https://testwatch.dev/eval), and how to score a trial like this for any tool is in [how to evaluate AI testing tools](https://testwatch.dev/blog/how-to-evaluate-ai-testing-tools).

How the generator writes, runs and checks a test is on the [AI Playwright test generator](https://testwatch.dev/playwright-test-generator) page.

## What this doesn’t catch

The loosening check reads code; it doesn’t run it. It can’t tell whether a new expected value is right, and it can’t judge a change between two checks that both use `.not`, since it can’t tell from the text which of those is stricter. It doesn’t know whether the original check was the right one to begin with, and it doesn’t judge what a check points at: in the PR example above, dropping the heading’s name passes it, and only the fix rules refuse it. A loosened first repair is thrown away only when the original failed every run on a wrong value or URL and the repair went green. After a timing or locator failure, or a check that failed only some of the time, only the agent’s instructions and the goal check stand between a loosened repair and your test. The goal check is an AI judgement: it can miss a gap, and a gap it finds can still ship with only a note. A test you have run against a broken copy of your app, and watched fail, is still the best proof that it can.

## Questions

**Why do AI-generated tests always pass?**

Usually because the test checks that a page loaded rather than that the outcome happened, because the expected value was copied from a screen that was already wrong, or because a failing check was rewritten until it passed. The last one leaves a trace in the diff: a deleted or looser assertion.

**Is toContainText worse than toHaveText?**

Not in itself. toContainText is the right choice when only part of the text is stable, like “Order #” in front of a number that changes every run. It becomes a problem when an exact check that failed is rewritten into it so that the run goes green.

**How do I know a test can fail at all?**

Break the outcome it is about and run it: change the total, empty the cart, stop the save. A test worth keeping goes red. Our eval does this for every case with planted bugs; the method is on [How we measure TestWatch](https://testwatch.dev/eval).

## Try it on your own app

Describe a user flow in plain English and TestWatch writes a Playwright test you can read and export. Passing runs make no AI calls.

Free: 5 tests, 500 runs a month, 2 apps and one daily schedule. Unlimited teammates, no card.

## Read next

- [Where AI test generation fails: every miss, explained](https://testwatch.dev/blog/ai-test-generation-failures)
- [Do AI-generated tests catch bugs? We planted some to see](https://testwatch.dev/blog/ai-written-e2e-tests-injected-bugs)
- [How to evaluate AI testing tools: count the false greens](https://testwatch.dev/blog/how-to-evaluate-ai-testing-tools)
- [How we measure TestWatch: false greens included](https://testwatch.dev/eval)
- [How TestWatch writes, runs and fixes a test](https://testwatch.dev/how-it-works)
