Thomas Osayi

November 22, 2026 · 9 min read · Thomas Osayi

How to add tests to an AI-generated app, and what to test first

A practical plan for adding tests to a Lovable, Bolt, v0 or Cursor app: Vitest and Playwright basics, testing auth, permissions and payments first, and CI on GitHub.

Most apps built with Lovable, Bolt, v0 or Cursor arrive with zero tests. That is fine while you are the only user and you click through everything yourself after each change. It stops being fine the day a prompt to "make the dashboard nicer" also rewrites the query that decides which records a user can see, and nobody notices for a week.

Tests are how you notice in minutes instead. You do not need hundreds of them. You need the right ten, running automatically on every change. Here is the order I add them in, the tools I use, and how to get them running in CI without turning it into a month long project.

Why do AI-generated apps need tests more than hand-written ones?

Because AI builders change more code per request than a human would, and they do not remember what they changed last time.

When you ask a builder for a small feature, it often regenerates whole files. A component that used to filter by the signed-in user can come back without the filter. A webhook handler can lose the line that checks the signature. The screen still renders, so the preview looks fine, and the bug only shows up when real data or a second user is involved.

A human developer would usually catch this in review. In a prompt-driven workflow there is no review step, so automated tests become the review. They are also the thing that makes a handoff safe: if you later bring in a developer, as I describe in "How to hand off your AI-built app to a developer," a test suite tells them what the app is supposed to do in a form they can run.

The goal is not perfect coverage. The goal is a safety net under the flows where a silent break costs you money, customers or trust.

What should I test first in an AI-built app?

Test the three things that hurt most when they fail silently: authentication, permissions and payments, in that order.

Authentication

Can a new user sign up, confirm, sign in, sign out and reset a password on the real domain? Redirect URLs that still point at a preview domain are one of the most common launch bugs I see, and a single end-to-end test catches them.

Permissions

Can user A see, edit or delete anything that belongs to user B? This is the test most AI-built apps fail. Supabase row level security policies and Firebase rules are easy to get wrong, and the app looks perfect from inside one account.

Payments

Does a successful checkout actually change the user's plan in your database? Does a cancelled subscription remove access? Does a webhook that arrives twice create two orders?

After those three, test whatever your app's core promise is: the booking that must not double book, the invoice total that must be right, the export that must include every row.

What tools should I use: Vitest, Playwright or both?

Use both, because they answer different questions: Vitest checks your logic quickly, and Playwright checks the app works in a real browser.

Vitest for unit and integration tests

Vitest is a test runner built on Vite, which is what Lovable and Bolt projects already use, and it works well in Next.js projects too. You install it with npm install -D vitest, add a "test" script that runs vitest, and name files with .test. or .spec. in them, for example pricing.test.ts. At the time of writing the current major version needs Node.js 22.12 or newer, so check your Node version before you start. Use Vitest for pure business rules: what a plan allows, how a total is calculated, whether a date range overlaps another booking.

Playwright for end-to-end tests

Playwright drives Chromium, Firefox and WebKit through your actual app. Running npm init playwright@latest creates playwright.config.ts, a starter test at tests/example.spec.ts, and offers to add a GitHub Actions workflow. You run everything with npx playwright test, and npx playwright test --ui opens a visual mode with time travel debugging that is very helpful when a test fails and you cannot see why.

If you only have time for one, start with Playwright. A few end-to-end tests catch more of the regressions AI builders cause than a pile of unit tests.

How do I write a permissions test that actually catches leaks?

Create two test users, sign in as one, and assert that the other user's data never appears, both in the interface and through the database API directly.

The interface check is a Playwright test: user A creates a record called something unique, signs out, user B signs in, and the test asserts that text is not on the page. That is useful, but it is not enough, because a leaky app often hides other users' rows in the interface while still returning them from the API.

The stronger check goes straight to the data layer. In a Vitest test, create a Supabase client with the public anon key, sign in as user B, and query the table that holds user A's records. The test passes only if the result is empty. Then try an update and a delete against A's row and assert they fail. This mirrors exactly what an attacker with your public key could do from a browser console.

For Firebase, the equivalent is the rules unit testing library against the local emulator, which lets you assert that a read as one user is denied on another user's document.

Run these against a local Supabase stack started with the Supabase CLI or a separate staging project, never production. If you want background on why these policies fail so often, my post "Is your Lovable or Bolt app leaking data? Check Supabase row level security" covers the usual mistakes.

How do I test payments without charging real cards?

Use Stripe test mode with test card numbers for the checkout flow, and the Stripe CLI to send webhook events to your local server for the part that updates your database.

Checkout itself is Stripe's job and you should not try to automate their hosted page heavily. What you own, and what breaks, is the code that runs after payment. So the most valuable tests are around your webhook handler:

  • Run stripe listen with --forward-to pointed at your local webhook route, then stripe trigger checkout.session.completed and assert the user's plan column changed.
  • Send the same event twice and assert you still have one order, not two.
  • Send an event with a bad signature and assert the handler rejects it.
  • Trigger a subscription cancellation and assert access is removed.

You can also unit test the pure function that maps a Stripe price ID to a plan in your app. That mapping is a common source of "paid but still on free" bugs. If you are already seeing that symptom, "Stripe payment went through but your app did not update? Fix the webhook" walks through the fixes.

How do I run tests automatically with GitHub Actions?

Add a workflow file under .github/workflows that installs dependencies, runs Vitest, installs Playwright browsers and runs Playwright on every push and pull request.

If you accepted the option during npm init playwright@latest, you already have .github/workflows/playwright.yml. At the time of writing it triggers on pushes and pull requests to main or master, runs npm ci, runs npx playwright install --with-deps, runs npx playwright test, and uploads the playwright-report folder as an artifact you can download when something fails.

Add one step before the Playwright step that runs npx vitest run, which runs once instead of watching. Put the URL and anon key of your staging Supabase project, plus Stripe test keys, into GitHub repository secrets and expose them to the workflow as environment variables. Never commit them.

Then turn on branch protection for main so a pull request cannot merge while tests fail. If you still edit in Lovable or Bolt, their commits land in the same GitHub repo, so the same checks run against changes the AI makes. That is the real payoff: every prompt now gets reviewed by your test suite.

What does this look like for a real app? A worked example

Here is an illustration with a made-up business: a dog grooming studio that built a booking app in Lovable with Supabase and Stripe deposits.

The owner's "must never break" list had five items: customers can sign in, customers only see their own bookings, staff see all bookings, a paid deposit confirms the booking, and two customers cannot book the same slot.

The first pass looked like this:

  • Three Playwright tests: sign up and sign in on the staging domain, book a slot and pay a deposit with a test card, and a staff login that sees every booking.
  • Two Vitest permission tests using the anon key: a customer cannot read or update another customer's booking, and a customer cannot read the staff notes table at all.
  • One Vitest test for the slot overlap function, with edge cases at the start and end of a slot.
  • A webhook test that sends the payment event twice and asserts one confirmed booking.

The permission test failed on the first run. The bookings policy allowed any signed-in user to read every row. That one test justified the whole exercise. The fix took an hour, and the test now guards it permanently. All of this ran in GitHub Actions in a few minutes per push.

How long does adding tests take, and what does it cost?

A first useful suite around auth, permissions and one payment flow is usually a few days of work, not weeks, if the app already works.

The time goes into three places: setting up test users and a staging database, writing the tests themselves, and fixing the real bugs the tests uncover, which is the part people forget to budget for. In my experience the bugs found are the valuable part.

On my side, adding a focused set of tests around one risky flow fits the Fix Plus Features package from $200 over five days, which covers up to three fixes plus one small feature. If the app is close to launch and needs tests, security fixes and deployment sorted together, that is the Finish and Launch package from $600 over ten days. If you only have one known bug, the Quick Fix from $60 covers it, though I would still recommend at least the permissions test.

Doing it yourself is realistic if you are comfortable in a terminal. Budget a weekend to get the first Playwright test green and CI running, then add tests one flow at a time.

The bottom line

You do not need to become a testing expert to protect an AI-built app. Write down the flows that must never break, cover sign-in, cross-user permissions and payments first, and run everything in GitHub Actions on every push. Ten good tests that run automatically beat a hundred that nobody runs. If you would rather have someone set it up and fix what the tests uncover, my fix your AI-built app service covers exactly that.

Questions, answered in one line

Do AI-built apps come with tests?

Usually not, because tools like Lovable and Bolt focus on generating working screens and rarely write or run automated tests unless you ask for them.

Should I use Vitest or Jest for a new test setup?

For a Vite or Next.js app started today, Vitest is the simpler choice because it shares Vite configuration and needs very little setup.

What is the difference between unit tests and end-to-end tests?

Unit tests check one function in isolation in milliseconds, while end-to-end tests drive a real browser through the app the way a user would.

Can I run tests against my production database?

No, run them against a local Supabase instance or a separate staging project, because tests create and delete data.

How much does it cost to add tests to an AI-built app?

Thomas Osayi can add a first set of tests around one risky flow from $200 with his Fix Plus Features package, or as part of a from $600 Finish and Launch engagement.

Sources

About the author

Thomas Osayi is a full-stack developer in Los Angeles studying computer science at Loyola Marymount University. He founded and built SQWAD, a SaaS platform Shopify brands use to run creator programs, and builds custom Next.js websites, SaaS MVPs and fixes for AI-built apps for businesses and founders.

See his work · Services and prices

Related articles

Fix, finish and launch your AI-built app

Built your app with Lovable, Bolt, v0, Replit or Cursor and got stuck? I fix the bugs, connect auth and payments, clean up the code and deploy it to production.

See the service