How to Test Code That AI Wrote
The AI builds fast but does not write tests. Here is how to add them without slowing down.
The AI Builds Fast. It Does Not Write Tests.
AI builders generate working apps quickly. But they skip tests. For a side project, that might be fine. For anything with real users, you need some level of testing to catch bugs before your users do.
You do not need 100% coverage. You need tests on the parts that would hurt most if they broke.
What to Test First
Authentication Flows
Login, signup, password reset, and session handling. If auth breaks, nobody can use your app. Test that:
- Users can sign up with valid credentials
- Invalid emails get rejected
- Password reset emails send correctly
- Logged-in users stay logged in across page refreshes
Payment Flows
If your app charges money, test the payment path end to end. A bug here costs you real revenue.
Core Business Logic
Whatever your app's main feature is, test that. A task manager should test creating, completing, and deleting tasks. A booking app should test making and canceling reservations.
Simple Testing Setup
Next.js apps work well with Vitest for unit tests and Playwright for end-to-end tests.
Install Vitest:
npm install -D vitest @testing-library/react
Write a basic test:
import { expect, test } from 'vitest'
test('formats price correctly', () => {
expect(formatPrice(1999)).toBe('$19.99')
})
For end-to-end tests, Playwright runs a real browser:
npm install -D @playwright/test
npx playwright install
Ask the AI to Write Tests
Here is the shortcut: after the AI builds your app, ask it to write tests for the most important flows.
"Write Vitest tests for the authentication utilities." "Write a Playwright test that signs up, logs in, creates a task, and marks it complete."
The AI is good at generating tests when you tell it what to cover. Review the tests to make sure they actually check meaningful behavior, not just that the page renders.
Related Articles
How the AI Builder Works Inside
From your prompt to working code. The pipeline, the choices we made, and why.
Make Your Next.js App Faster
Image optimization, code splitting, and caching strategies. The stuff that actually moves the needle.
Row Level Security in Supabase
How to make sure users can only see their own data. Step by step RLS policies explained.
Ready to try it?
Build your first app in a few minutes.
Start Building