Skip to content
groundworkv0.2

Testing

Tests are how an agent proves its work, and how you keep it from breaking yesterday's work.

8 min read · Last reviewed November 20, 2026

Testing

When an writes the code, tests become your main way to check it. A good test suite lets an agent work autonomously, because it can check itself.

You'll be able to#

  • Know which kinds of tests to ask for, and how many
  • Use tests to drive agent work (test-first prompting)
  • Spot tests that pass without actually testing anything

The mental model#

The testing trophy / pyramid: lots of fast checks at the bottom (types, lint), a solid middle of integration tests (real database, real HTTP), and a few end-to-end tests covering critical user flows. Each layer catches different bugs.

Key concepts#

  • Static checks: TypeScript and linters (ESLint/Biome, Ruff). They're free, instant and catch whole classes of bugs.
  • Unit tests: A single function in isolation. Best for pure logic (pricing, parsing, permissions).
  • Integration tests: Several pieces working together, such as an route plus a real test database. The best value for most apps.
  • End-to-end (E2E): A real browser clicking through the app (Playwright). Slow but realistic. Reserve these for critical paths like signup, checkout and login.
  • Mocks / fakes: Stand-ins for external services. Overusing mocks produces tests that test the mocks.
  • Fixtures / factories: Reusable test data builders.
  • Coverage: The percentage of lines executed by tests. Treat it as a hint, not a goal.
  • Regression test: A test written for a bug, so the bug can never come back.
  • TDD with agents: Write (or have the agent write) failing tests from the spec first, then let the agent implement until they pass.
  • Evals: The equivalent of tests for LLM-powered features: graded examples of model behaviour.

Decisions you make (not the agent)#

Your call, not the agent's

DecisionSensible defaultChoose otherwise when…
RunnerVitest (JS/TS), pytest (Python)Existing Jest setup → keep it
E2EPlaywright for 3–10 critical flows—
DB in testsReal Postgres (Docker/Testcontainers or a branch DB)Pure logic → no DB
CIAll checks block merge—
Bug workflowReproduce with a failing test first, then fix—

What good output looks like#

  • Tests describe behaviour in plain names and check results, not implementation details
  • Every test would fail if the behaviour it covers were broken
  • Edge cases and boundaries (the exact limit, empty input, one past the limit) are tested
  • Integration tests use a real database, and end-to-end tests cover only the critical flows
  • No skipped tests, no assertions that can't fail

Red flags#

  • Tests that assert the mock was called and nothing else
  • expect(true).toBe(true), or snapshot tests nobody reads
  • The agent "fixing" a failing test by changing the assertion to match the buggy output
  • Skipped tests (.skip, xit) appearing in a diff
  • No tests for permission and ownership rules
  • Common agent mistakes: a test that recomputes the formula it is testing, so it agrees with the code even when the code is wrong; only "typical" values, with no boundary cases; end-to-end tests that use fragile CSS selectors and fixed waits (Playwright recommends user-facing locators such as roles, and assertions that wait); tests that call a real third-party service that you don't control

Worked example#

Task: Add a rule: orders of 100 or more get a 10% discount.

You prompt: "Add a discount for orders of 100 or more, and write tests." The agent writes if (total > 100) and tests with totals of 50 and 150. Both pass. Coverage is 100%.

What a good result contains: the comparison written as the spec says (>= 100), and tests at the boundary: exactly 100, just under (99.99) and just over, plus zero and negative input.

The wrong turn: the code is wrong at exactly 100, and the tests can't tell. Coverage measures that lines ran, not that anything was checked. makes the problem visible: a tool such as Stryker changes the code (turning a boundary comparison into something else) and reruns the tests. If every test still passes, the mutant "survived", which means the tests aren't covering that code well. A surviving boundary mutant points straight at the missing boundary test.

How review catches it: ask what does each test check that would break if the rule were wrong? Try the sabotage by hand: change >= to > and run the tests. Nothing fails, so add the boundary tests. For important logic, run a mutation tool and read the survivors. Re-prompt for tests from the spec first, including every boundary.

Sample prompts#

Weak vs strong#

Strong prompt
Before implementing <feature>, write failing tests from this spec: <spec>.
Cover the happy path, validation errors, permission denials, and edge cases
(<list>). Show me the tests and wait. After I approve, implement until all tests
pass without modifying the tests.

Why it works: The tests become the spec, and "without modifying the tests" stops the agent from cheating.

What changed

  • Spec first: tests come from the rules, not from the existing code
  • Cases are named: happy path, validation errors, permission denials and edge cases
  • Review point: the agent stops so you can read the tests
  • No editing tests to get them green
Prompt
Set up testing for this project: Vitest for unit/integration with a real Postgres
via Testcontainers, Playwright for E2E of signup → create project → invite
member, and a GitHub Actions workflow that runs type-check, lint, and all tests
on every PR.

Why it works: It names the runner, the database approach and the critical flow for each layer, and puts all of it into CI, so the tests protect every future change.

Find tests that can't fail#

Prompt
Review the tests for <module>. For each test, say what behaviour it would catch if broken, and whether it would still pass if the implementation were wrong. Flag tests that only assert a mock was called, recompute the code's own formula, or check things that cannot fail. Then list the boundaries and edge cases that have no test. Don't change anything yet.

Why it works: It asks the question that coverage can't answer: would this test notice a bug?

Sabotage the code on purpose#

Prompt
For <module>, make five small deliberate breakages one at a time (for example change >= to >, flip a condition, remove a check, return early, change a constant). After each one, run the tests and record whether anything failed, then revert it. Report which breakages no test caught and write the tests that would catch them.

Why it works: This is mutation testing done by hand. A breakage that no test notices is a hole in the suite.

Fix a flaky browser test properly#

Prompt
This end-to-end test is flaky: <paste>. Rewrite it to use user-facing locators (by role or visible text) instead of CSS selectors or XPath, replace fixed waits with assertions that wait for the expected state, and make the test independent of other tests by creating its own data. Explain what made it flaky.

Why it works: Playwright's best practices recommend exactly these changes: user-facing locators, assertions that wait, and isolated tests.

Check your understanding#

Check your understanding

1/4A suite has 100% line coverage. What does that tell you?
2/4In mutation testing, what does a surviving mutant mean?
3/4Which locator is preferable in an end-to-end test?
4/4You tell the agent to implement until the failing tests pass. What must you add?

Checklist#

  • Type-check and lint run in CI
  • Integration tests cover API routes, including auth and ownership
  • E2E tests cover the critical flows
  • Every fixed bug has a regression test
  • Boundaries (the exact limit, one below, one above) are tested
  • I have checked that the tests can fail, by sabotaging the code or running a mutation tool
  • End-to-end tests use role-based locators and assertions that wait

Go deeper#