Testing Guide for AI Coders
Make sure your project works before your users find out it doesn't. Testing catches bugs so you can ship with confidence.
In this chapter
- What testing is and why it matters even for small projects
- The kinds of tests AI can write for you
- How to ask AI to add tests to an existing project
- When testing is overkill (and when it's a lifesaver)
Why Test Your Project?
Testing means checking that your website or app does what you expect. You wouldn't hand in an essay without proofreading it: testing is proofreading for your project.
Types of Tests
Think of these as different levels of checking, from tiny checks to big-picture tests.
Recommended Testing Tools
Tell your AI tool which one to use, and it will set everything up for you.
What to Test First
You don't need to test everything. Start with what matters most.
-
1
Forms and user input If someone fills out a sign-up form and it breaks, you lose a user.
-
2
Payment and checkout flows Money is involved. This must work perfectly every time.
-
3
Login and authentication If users can't log in, nothing else matters.
-
4
Core features your users rely on The main thing your app does: make sure it actually does it.
-
5
Navigation and routing Can users get to every page? Do links work?
-
6
Edge cases and error states What happens when someone submits an empty form or enters weird data?
Ask Your AI Tool to Write Tests
Copy these prompts and paste them into your AI coding tool. It will set up testing and write tests for you.
“Add Vitest to my project for unit testing. Set up the configuration file and create a simple example test that passes. Also add a test script to my package.json so I can run tests easily.”
“Write tests for my contact form. Test that: the form renders correctly, required fields show an error when submitted empty, the email field rejects invalid emails, and a successful submission shows a confirmation message. Use Vitest and React Testing Library.”
“Set up Playwright for end-to-end testing. Create tests that: open the homepage, check the navigation links work, fill out the main form and submit it, and verify the success page appears. Make the tests run in headless mode.”
“Look at my project and write tests for the most critical user flows. Focus on anything involving forms, authentication, or data submission. Use Vitest for unit tests and explain what each test checks.”
Prompt This
Copy-paste these prompts into your AI tool to apply what you just learned.
“Add basic tests to my app. Write tests for my [component/function/API route] that check [expected behavior]. Use Vitest and Testing Library.”
“My app has a bug where [describe bug]. Write a test that reproduces this bug, then fix the code so the test passes.”
Frequently Asked Questions
Do I really need to write tests?
For a personal project or prototype, manual testing is fine. For anything others will use (especially if it handles data, money, or authentication), automated tests catch bugs before your users do. Start with a few tests for your most critical features.
What should I test first?
Test the things that would be most embarrassing if they broke: user signup/login, payment processing, and any feature that handles sensitive data. Then add tests for common user flows like form submissions and navigation. Don't try to test everything at once.
Can AI write tests for me?
Yes, and it's surprisingly good at it. Tell your AI tool: 'Write tests for my signup form. Test that it validates email format, requires a password, and shows an error for duplicate emails.' AI tools understand testing frameworks like Vitest and Jest.