← Back to my notes

I deleted half our backend tests

Nearly 1,000 fewer test files and 30% less CI compute. Why we removed them, what we kept, and how I want to stop low-value tests from coming back.

Short version

If you don’t want to read the whole article and you want to improve your test strategy, give your coding agent this prompt and review the findings before deleting anything: some tests could just need a better assertion or a better setup.

Explore my test suite and identify tests (or groups of tests) which are tautological, too structure-sensitive, or where the mocks don’t match reality.

Prompt extracted from Matt Pocock’s video about the importance of software fundamentals in React.

What changed

I deleted about half of our backend test files. The suite went from 1,910 files to 916, with roughly 174,000 lines removed.

In the first three days after that cleanup, our continuous integration (CI) pipeline, which runs checks on every pull request, used 30% fewer machine minutes per run. The original rounded median times were:

  • Unit tests, which exercise small pieces of code: 11 → 7 minutes.
  • Tests that use a real database: 11.5 → 6.5 minutes.
  • A full CI run: 14.5 → 11.5 minutes.

Machine minutes add up the time used by every machine. They differ from how long I wait for a run to finish, because several jobs run at once. Alongside deleting tests, we combined small files and spread long-running tests more evenly across machines. These results reflect that whole cleanup.

We kept tests around risks that mattered to us: one agency accessing another’s data, permissions, sensitive patient information appearing in logs, money calculations, reading data from external systems, and jobs recovering after a crash without repeating an external action. Tests that had caught a real bug in the previous two months were kept or rewritten.

Why?

Coding agents love to create garbage tests. They can repeat the implementation, mock away everything that could fail, and give you a green check without testing anything useful.

A test costs more than the time it takes an agent to write it. It runs on future changes. Someone has to understand it when it fails. And if it checks the wrong thing, it can make a broken change look safe.

That last part worried me most. A passing test with a name like “prevents access to another agency’s data” sounds reassuring. But the name doesn’t tell me whether the test ever created another agency’s data, or whether a mock had already forced the result to be empty. A mock is a substitute for a real dependency, such as a database or an external API.

Weak tests also make harmless changes expensive. If I move logic into a different function and the behavior stays the same, tests tied to the old arrangement can still fail. The work becomes updating tests to match the implementation. That maintenance buys little confidence about whether the product works.

We accepted a trade-off when we cut the suite: some behavior outside our risk list became untested. Faster CI alone doesn’t prove every removal was right. I still need to understand which risks have coverage and which don’t.

How?

Some of these examples will feel very basic. But I found a lot of them in my own tests, and I’m coding with Opus 5.5. Unbelievable, isn’t it?

We looked at what each test could actually prove. The useful question was: what mistake would make this test fail? Sometimes the answer justified deleting it. Sometimes it showed us how to improve it.

These simple examples show the patterns to look for and what a stronger check looks like. They use Jest-style assertions, which describe the result a test expects.

Tautological tests: borrowing the answer

A tautological test repeats the implementation’s answer instead of checking it against an independent expectation.

Suppose a checkout adds 10% tax. The production function, totalWithTax, calls a helper named taxFor. The test calls that same helper to calculate its expected result:

const subtotal = 100;
const expected = subtotal + taxFor(subtotal);

expect(totalWithTax(subtotal)).toBe(expected);

If taxFor mistakenly charges 5%, both sides return 105. The test passes with the wrong total.

Use the business rule to work out the expected answer:

// $100 plus 10% tax is $110.
expect(totalWithTax(100)).toBe(110);

A shared helper can be useful when checking that components agree. It just can’t independently prove that the helper’s own calculation is right. Choose expected values from a requirement or a worked example, including the edge cases that matter.

Empty setups: nothing that could go wrong

Imagine a notes app where users should only see their own notes. This test starts with an empty database:

expect(await listNotes('alice')).toEqual([]);

It passes even if listNotes returns every note in the database. There are no notes to leak.

Put the permission boundary under pressure:

const aliceNote = await createNote({
  owner: 'alice', text: 'My shopping list',
});
await createNote({ owner: 'bob', text: 'My private plans' });

expect(await listNotes('alice')).toEqual([aliceNote]);

Now returning Bob’s note fails the test. Returning nothing also fails, so the test checks both access to Alice’s own data and exclusion of someone else’s. The setup makes the intended mistake observable.

Unrealistic mocks: the dependency behaves differently

A mock can make a test easier to write while removing the behavior you need to check.

For example, suppose loadProfile fetches a profile and should report “Could not load profile” when the server returns HTTP 503, meaning the service is unavailable. This mock makes fetch reject immediately:

const fetchMock = jest.spyOn(globalThis, 'fetch');
fetchMock.mockRejectedValue(new Error('HTTP 503'));

await expect(loadProfile()).rejects.toThrow();

But an HTTP error status does not make real fetch reject. It resolves with a response, and the caller must inspect its status. A rejected promise models a different failure, such as a network error. The Fetch documentation explains this distinction.

Make the mock return the response the real server would produce:

fetchMock.mockResolvedValue(new Response('Unavailable', {
  status: 503,
}));

await expect(loadProfile()).rejects.toThrow('Could not load profile');

This checks whether loadProfile handles an unsuccessful response. If it forgets to check response.ok, the test can expose that mistake. Keep a separate case for network failures when they need different handling.

The same reasoning applies to database fakes that ignore filters, storage fakes that never fail, or payment mocks that always succeed. A mock needs to preserve the dependency behavior relevant to the test.

Structure-sensitive tests: checking how instead of what

These tests depend on implementation details that can change without changing the intended behavior.

Suppose the submit button should be disabled while a sign-up form is empty:

render(<SignupForm />);

expect(screen.getByRole('button', { name: 'Sign up' }))
  .toHaveClass('opacity-50');

That checks a styling choice. The button could look faded and still allow submission. A harmless CSS change could also break the test.

Check the required behavior directly:

render(<SignupForm />);

expect(screen.getByRole('button', { name: 'Sign up' }))
  .toBeDisabled();

The component can change its CSS or internal structure while this check remains useful. If the requirement is about appearance, test appearance deliberately. If it’s about preventing submission, test that behavior.

Exact private-method calls, internal row counts, or pieces of generated SQL can create the same coupling. Before asserting them, ask whether they are part of a requirement or just how the code happens to work today.

Broad error checks: failing for the wrong reason

A test can pass because something broke before it reached the behavior you wanted to exercise:

await expect(register('not-an-email')).rejects.toThrow();

That accepts any error. A TypeError from broken setup satisfies it just as well as a validation error.

If invalid email addresses must produce “Invalid email,” name that expectation:

await expect(register('not-an-email')).rejects.toThrow('Invalid email');

Use the error type, code, or message that represents the contract. Avoid pinning incidental wording when a stable error type or code is available. The setup still has to reach validation, but an unrelated failure can no longer satisfy the assertion as easily.

These tests usually need tightening, not deletion. We strengthened about 150 broad error checks in our own suite.

Next steps

We want to keep our tests useful as the codebase grows, so we’re exploring ways to keep improving the suite. That could mean skills that guide our coding agents, automated guardrails that catch weak tests, or a combination of both. We’re still trying out options. I’ll keep you posted on what works.

A mistake worth sharing.

Working through something similar? Leave me a note on any part of this page.