Write unit tests with an AI assistant
Tests are how you trust AI-written code.
What to do
- Ask for tests of current behavior before asking for changes.
- List edge cases explicitly: empty, huge, negative, Unicode, time zones, nulls.
- Run the tests; a test that never fails proves nothing, so break the code once to see it fail.
- Keep tests readable; ask the bot to name tests as sentences.
Copy this prompt
Write unit tests for this function using [framework].
- Cover normal cases, edge cases (empty, null, boundary values) and error handling.
- One behavior per test, descriptive names.
- Don't change the function.
Function:
[paste]Check the bot's work
Run the suite and check coverage of the branches you care about.
Questions
Can I trust the bot on write tests first?
Use it to plan and explain, then verify. Run the suite and check coverage of the branches you care about.
Which bot works best?
Grok Bot, ChatGPT, Claude and Gemini all handle this prompt. Paste the same prompt into two and compare; disagreements show where to check a source.
Where these facts come from
- OWASP Top 10
- CISA: Secure by Design
- GitHub Docs: Secret scanning
- W3C: WCAG overview
- Open Source Initiative: Licenses
- NIST SP 800-218: Secure Software Development Framework
Tools, features and prices change often. We don't list prices; check each vendor's official pricing page. Never paste secrets into a prompt. Checked Oct 30, 2026.
Coding with bots · Everyday workflows: all lessons → Next: Debugging with a bot →