How to Test AI-Generated Code (Without Being a QA Engineer)

Practical testing strategies for vibe coders. When to trust AI code, when to verify, and prompt patterns for test generation.

By vibecodemeta 7 min read
testing qa best-practices vitest

AI generates code fast. But how do you know it’s correct?

Most vibe coders have the same instinct: ship it and see what breaks. That works until something breaks in production and your users find out before you do.

There’s a middle ground. You don’t need QA engineers. You don’t need 100% test coverage. You need enough validation to sleep at night.

This guide covers the testing patterns that work for AI-generated code, when to trust the AI, and how to write tests faster than you can write code.

The Testing Pyramid for Vibe Coders

Traditional testing advice says you need:

  • 70% unit tests
  • 20% integration tests
  • 10% end-to-end tests

For AI-generated code? Flip it.

The Vibe Coder Testing Pyramid:

  • 10% unit tests (trust the AI here)
  • 30% integration tests (verify the parts work together)
  • 60% manual testing (your judgment is the safety net)

This ratio makes sense because:

  1. AI is good at writing isolated functions. Unit tests are expensive relative to the confidence they give.
  2. AI often misses how components interact. Integration tests catch those bugs.
  3. Manual testing is where you catch the weird edge cases AI didn’t anticipate.

What to Trust vs. What to Verify

Trust These (AI Nails Them):

Algorithmic functions: Sorting, filtering, string manipulation, mathematical operations. AI understands these patterns deeply. If it generates a bubble sort and you test it with 3 arrays, it’ll work for all arrays.

Standard CRUD operations: Create, read, update, delete patterns. These are so standardized that AI almost never gets them wrong. Especially with databases like Supabase or Firebase where the patterns are explicit.

UI component structure: AI generates React components that render correctly. The layout, the JSX, the conditional rendering—this usually works. Small styling tweaks might be needed, but the structure is sound.

API integration (happy path): If you’re fetching from an API and the API works, AI will write code that works. The happy path is predictable.

Verify These (AI Sometimes Misses):

Error handling: AI generates try-catch blocks, but the error messages are often generic or misleading. Test what happens when the API fails, the network is down, or the user input is invalid.

Edge cases: Empty arrays, null values, undefined responses, zero values. AI thinks about happy paths. You need to think about sad paths.

Timing and async code: Race conditions, promise chains, cleanup functions. AI’s async code often works, but there are subtle bugs around timing and state management.

User interactions: Form validation, button click handlers, keyboard navigation. AI generates the handlers, but real user behavior is weirder than AI anticipates.

Performance: AI doesn’t think about whether code will be slow. If you’re rendering 10,000 items or running expensive calculations, you need to verify that’s acceptable.

The Testing Workflow

Step 1: Manual Testing First

Don’t write automated tests first. Use the feature. Click the buttons. Enter weird data. Try to break it.

If you find bugs, note them. Most bugs you find here are things AI couldn’t have anticipated because they require domain knowledge.

This usually takes 15-30 minutes and catches 80% of the real issues.

Step 2: Write Tests for the Bugs You Found

Only test what broke. Don’t test everything.

Prompt your AI tool:

“I found a bug in this code. When the user [does this], [this breaks]. Write a test that reproduces the bug. Then fix the code to make the test pass.”

AI is excellent at this. You describe the problem, it writes a failing test, fixes the code. This is faster than you fixing it manually.

Step 3: Automation Tests for Regressions

Once the bug is fixed, keep the test. This prevents the same bug from coming back.

Prompt:

“I have a test that verifies [behavior]. Add 3 more tests that cover related scenarios.”

AI will generate variations. Some are useful. Some are redundant. Delete the redundant ones.

Practical Testing Patterns

Testing API Calls

This is where AI struggles most. Prompt carefully:

“Write a test for this function using Vitest and MSW (Mock Service Worker). The function calls [endpoint] and returns [data structure]. Test:

  1. Successful response with valid data
  2. Network error (simulate fetch failing)
  3. Invalid response (API returns unexpected data)
  4. Empty response (API returns null)”

MSW is a mock HTTP library that intercepts requests. AI understands it. You get good coverage without managing complex mocks.

Testing React Components

AI generates component tests, but they’re often shallow. Prompt for what actually matters:

“Write a test for this React component that:

  1. Renders the component
  2. Simulates a user typing in the input field
  3. Verifies that clicking the button triggers the callback
  4. Checks that the loading state shows while the request is in flight
  5. Verifies that the error message appears if the request fails”

Use Testing Library (not Enzyme). AI knows Testing Library. Your tests will focus on user behavior, not implementation details.

Testing Database Operations

If you’re using Supabase or Firebase, you need to test that your RLS policies actually work:

“Write a test that:

  1. Creates a user account
  2. Verifies that the user can read their own data
  3. Verifies that the user cannot read other users’ data
  4. Verifies that the user cannot update other users’ data”

This requires setting up test databases or mocking. Ask AI to handle the setup. This is tedious and easy to get wrong. AI is better at it than you are.

Test Generation Prompts That Work

Pattern 1: The Full Test Suite

“I have this function: [code]. Write comprehensive tests for it. Include happy path, error cases, and edge cases. Use Vitest. Output should be copy-paste ready.”

AI will generate 5-10 tests. 50% will be valuable. 50% will be obvious or redundant. Keep the valuable ones, delete the rest.

Pattern 2: Specific Scenario Testing

“Write a test for the scenario where [user does this complicated thing]. Include mocking for [API/database calls].”

This is more targeted. You get fewer tests but higher quality.

Pattern 3: Integration Testing

“Write an integration test that:

  • Creates a user
  • User logs in
  • User creates a post
  • User deletes the post

Mock the API/database as needed. Use Vitest.”

Integration tests catch things unit tests miss: missing parameters, wrong API endpoints, async race conditions.

When You Can Skip Testing

You don’t need tests for:

  • UI styling: CSS doesn’t need tests. If it looks right, it’s right.
  • Third-party library integrations: If you’re using a well-tested library correctly, you don’t need to test that it works.
  • One-off scripts: If it’s a migration script you’ll run once, manual testing is enough.
  • Configuration files: Config files don’t need tests.

Test the code you wrote (or AI wrote for you). Don’t test the entire framework.

Trust But Verify

Here’s the real principle: AI is fast, but it’s not always correct. The right approach is skepticism paired with quick verification.

When AI generates code:

  1. Skim it for obvious bugs (infinite loops, wrong variable names)
  2. Use it manually and try to break it
  3. If it works, ship it
  4. If users find bugs, write tests for those specific bugs
  5. Move on

This isn’t perfect. You’ll occasionally miss bugs. But you’ll ship 10x faster than if you were writing tests first and code second.

The vibe is: code fast, test what matters, learn from production.

The Practical Reality

You’re not building a nuclear reactor. You’re building a product. If you have a bug, you fix it. Users will tell you what’s broken before your tests will.

But tests prevent embarrassing bugs. Tests prevent regressions. Tests let you refactor without fear.

Write tests where it matters. Let AI generate them. Move fast.

Next Steps

  1. Ship something without tests (if you haven’t already)
  2. Use it. Find the bugs.
  3. Write tests only for the bugs you found
  4. Deploy with confidence
  5. Iterate

That’s the workflow. Tests are a tool, not a religion.

Join the Discussion