Technical how-to

How to write test cases with AI.

Test case generation is one of the highest-leverage engineering uses of AI. Tests are tedious to write but critical to maintain quality. Claude can produce ~70% of standard test cases automatically. Engineers refine the edge cases. Here is the workflow.

Where AI does well

The 3 test types

1. Unit tests from function signatures. Given a function definition + intent, AI generates input/output test cases including edge cases.

2. Integration tests from API specs. Happy path + error paths + auth checks.

3. E2E tests from user stories. Test scripts that walk through user workflows.

The unit test prompt

Use this

Generate unit tests for this function: [PASTE FUNCTION]

Intent: [WHAT THE FUNCTION SHOULD DO]
Test framework: [JEST / PYTEST / etc]
Existing test patterns in this codebase (paste 1-2 examples): [PASTE]

Generate tests for:
1. Happy path with typical inputs
2. Edge cases (empty inputs, null, max/min values)
3. Error conditions (invalid input, expected exceptions)
4. Boundary conditions specific to this function

Match the style of the existing tests.

Flag any test that requires inputs you had to guess at — engineer should verify those.
What AI misses in test generation

Stay human

Business logic edge cases that require domain knowledge.

Performance tests with realistic data volumes.

Security tests requiring threat modeling.

Tests for code with poor or no documentation — AI does not know intent, so cannot test against it.

Related

Related how-tos

Want QA workflows built?
Implementation includes engineering workflow design.
See Implementation → Book the AI Audit