Short answer: Use unit tests to pin down the logic an agent writes: calculations, rules and edge cases, checked on every build. Use end-to-end tests to prove the user journeys work in the running app. For AI-generated code you need both, but end-to-end tests matter more than before, because they check the result independently of the agent that wrote the code.

Your agent built a clinic booking app, and every test is green. Then a patient books the last slot of the day, and a second patient gets the same slot. The tests passed because the agent wrote them too, from the same wrong idea of what "available" means.
That is the new problem with AI-written code. The old advice on testing still holds, but who writes the tests now matters as much as how many there are.
In this guide, you'll learn:
- Definitions
- Unit and end-to-end tests side by side
- When to choose unit tests
- When to choose end-to-end tests
- Where an AI software factory fits
The rest of this page covers it in order.
Definitions
Unit test. "Unit testing verifies the smallest testable parts of an application, such as functions or methods, in isolation" (Graphite). In the clinic app, a unit test calls isSlotAvailable() with a fake calendar and checks the answer.
End-to-end (E2E) test. "E2E testing simulates real user scenarios, validating the system's functionality and performance from start to finish" (same source). In the clinic app, an E2E test opens the booking page in a browser, picks a doctor and a slot, submits the form and checks that the confirmation appears and the slot disappears for the next patient.
Integration test sits between them: it checks that combined parts work together, such as the booking service and the database. This page focuses on the two ends, because that is where teams argue.
AI-generated code here means code written by a coding agent or an AI software factory, then reviewed and merged by people.
Why AI-written code changes the balance
Three things are different when an agent writes the code.
- The tests and the code can share one mistake. If an agent misreads the requirement, it writes wrong code and matching unit tests. Everything passes. Martin Fowler's site warns that agents often do not follow their written instructions, which gives a "false sense of control" (martinfowler.com).
- There is more code to check. QA Wolf positions its platform for teams whose coding agents "ship faster than anyone can review," and cites a sample of 20,000 pull requests in which 1 in 25 had a bug (vendor figures) (QA Wolf).
- Changes spread further. An agent fixing one screen can break a connected one it never opened. Tools now map a change to the tests it affects: mabl's October 2026 harness adds a knowledge graph that "highlights coverage gaps" for each change (SD Times).
None of this makes unit tests less useful. It makes them less sufficient.
Unit and end-to-end tests side by side
| Aspect | Unit tests | End-to-end tests | Source |
|---|---|---|---|
| What it checks | One function or method in isolation | A full user journey through the running app | Graphite |
| Speed | Fast | Slow | Graphite |
| Cost to run and keep | Low; maintenance easy | High; maintenance challenging | Graphite |
| When it usually runs | Every build | Nightly or pre-release (or per pull request with newer tools) | Graphite; Momentic |
| When it fails, you learn | Exactly which function broke | Which journey broke, not always why | Graphite |
| Independent of the code's author? | Often written by the same agent | Can be written from the user's journey by a separate agent or person | This page's analysis |
| Typical AI help in 2026 | Generated with the code; CodeRabbit generates unit tests on its Team plan | Playwright test agents; QA Wolf, mabl and Momentic agents | CodeRabbit pricing; Playwright |
| Flakiness handling | Rarely an issue | Retries and self-healing; QA Wolf retries up to 3 times per run | QA Wolf pricing |
When to choose unit tests
- The logic has many cases. Fees, discounts, tax, slot rules, date math. A unit test can check dozens of inputs quickly, and Kiro, for example, verifies specs with property-based tests "across hundreds of cases" (Kiro).
- You want feedback on every build. Unit tests are fast and precise enough to run each time an agent pushes a change.
- You need to know exactly what broke. A failing unit test names the function; a failing E2E test names a journey.
- The code has no screen. APIs, background jobs and data imports are better covered at the unit and integration levels.
- You can write the test before the code. When a person writes the key unit tests from the spec first, they stop being the agent's own opinion of the requirement.
When to choose end-to-end tests
- The journey is what the client pays for. Booking, sign-up, checkout and payment should be clicked through, not inferred from passing functions.
- The same agent wrote the code and its unit tests. An E2E test written from the user's side is the independent check.
- Changes touch shared screens or flows. A change to the booking form can break reminders and the doctor's calendar view. Only a run through the app shows it.
- You need proof for someone else. Clients and auditors understand "a patient booked, got an email and cancelled" more readily than a coverage number. QA Wolf and Momentic report failures with recordings, screenshots or PR checks (QA Wolf pricing; Momentic).
- You're testing AI features. QA Wolf supports "semantic and non-deterministic assertions," and mabl says it can "Validate dynamic outputs" (QA Wolf; mabl).
A warning about AI-written E2E tests. Playwright's Healer agent runs the suite and repairs failing tests, or skips them "if it believes the feature is broken" (Playwright docs). A skipped test is not a passing test. Review what the healer changed.
Tools for each layer
- Playwright is free, open source and maintained by Microsoft. It runs Chromium, Firefox and WebKit, and its Test Agents (Planner, Generator, Healer) work with VS Code, Claude Code, Codex and OpenCode. You host the runs and CI yourself (Playwright).
- QA Wolf writes, runs and maintains E2E tests and exports them as Playwright and Appium code. It charges USD 1 per web test run and USD 2 per mobile or desktop run, as of November 2026 (QA Wolf pricing).
- mabl covers web, mobile and API tests in one suite and posts GitHub PR status checks. Pricing is by quote (mabl pricing).
- Momentic stores tests as YAML in your repo and can test a PR's preview deployment. Free includes USD 50 of usage per month, as of November 2026 (Momentic pricing).
For a wider list, see Best AI testing tools for AI-generated code.
Where an AI software factory fits
A coding agent writes code and, often, its tests. An AI software factory adds a separate step whose job is to test what was built.
Coding agents automate the developer. Devfab automates the development lifecycle. In Devfab, the QA agent is separate from the dev agents. It runs UI and flow tests, with screens, buttons and user journeys clicked end to end, plus logic tests. A workspace switch, "QA agent · review before Done", sets it to review each ticket before it closes.
Two other parts help with the problems above:
- ChainFlow maps which functions and APIs call each other and what is deployed. When a dev agent changes the booking service, it can see that reminders, the doctor's calendar and cancellation emails depend on it.
- The plan is approved by a person before tickets exist, so the requirement the tests check is one a human has read.
Devfab's honest limits: it is in Beta, with a smaller community and fewer integrations than dedicated test platforms, and it is not an editor for writing tests by hand. If you need a standalone E2E platform for apps built elsewhere, the tools above are the better fit. Read more in What is a QA agent? and AI code review vs QA agent.
FAQ
What is the difference between unit tests and end-to-end tests?
A unit test checks one small piece of code, such as a function, on its own. An end-to-end test runs the whole app the way a user would, from screen to database and back. Unit tests are fast, cheap and precise; end-to-end tests are slower and harder to maintain but prove a full journey works.
Are unit tests enough for AI-generated code?
Rarely. When the same agent writes the code and its unit tests, both can share the same misunderstanding of the requirement, so the tests pass and the feature is still wrong. End-to-end tests written from the user's journey give an independent check.
Can AI write end-to-end tests?
Yes. Playwright ships Planner, Generator and Healer test agents, and platforms such as QA Wolf, mabl and Momentic use agents to write, run and maintain end-to-end tests. Review what they produce: Playwright's Healer can skip a test if it believes the feature is broken.
How many end-to-end tests should a project have?
Fewer than unit tests. Cover the journeys that cost money or trust when they break, such as sign-up, booking, checkout and payment, and leave edge cases in calculations to unit tests. Then add an end-to-end test each time a bug escapes to users.
Read next
- What is an AI software factory?
- AI code review vs QA agent: what each one catches
- How to stop AI coding agents from breaking existing code
Want a separate QA agent that clicks through every journey? Try Beta
Sources (checked November 2026): Graphite: unit vs integration vs E2E testing; martinfowler.com: Understanding spec-driven development (Oct 15, 2025); Playwright; Playwright Test Agents docs; QA Wolf; QA Wolf pricing; mabl AI test automation; mabl pricing; SD Times: mabl agentic testing harness (Oct 2026); Momentic; Momentic pricing; CodeRabbit pricing; Kiro.
Frequently asked questions
What is the difference between unit tests and end-to-end tests?
A unit test checks one small piece of code, such as a function, on its own. An end-to-end test runs the whole app the way a user would, from screen to database and back. Unit tests are fast, cheap and precise; end-to-end tests are slower and harder to maintain but prove a full journey works.
Are unit tests enough for AI-generated code?
Rarely. When the same agent writes the code and its unit tests, both can share the same misunderstanding of the requirement, so the tests pass and the feature is still wrong. End-to-end tests written from the user's journey give an independent check.
Can AI write end-to-end tests?
Yes. Playwright ships Planner, Generator and Healer test agents, and platforms such as QA Wolf, mabl and Momentic use agents to write, run and maintain end-to-end tests. Review what they produce: Playwright's Healer can skip a test if it believes the feature is broken.
How many end-to-end tests should a project have?
Fewer than unit tests. Cover the journeys that cost money or trust when they break, such as sign-up, booking, checkout and payment, and leave edge cases in calculations to unit tests. Then add an end-to-end test each time a bug escapes to users.



