Testing strategies

Writing, running, and maintaining tests alongside Claude

Tests are how you trust Claude’s code

Working with Claude Code without tests is like auditing financial records without receipts — you’re trusting what you see, not what you can verify. Tests make Claude Code dramatically safer by letting you verify every change before it ships.

Test-as-you-build workflow

"We're going to build [feature]. For each function we write, we'll immediately write tests for it before moving on. This is non-negotiable — no moving to the next function until the current one has passing tests."

Writing tests for existing code

"Read /src/transforms/pricing.js and write comprehensive tests for every exported function in /tests/transforms/pricing.test.js.

For each function, test:
1. The happy path (normal expected input)
2. Edge cases (empty input, null, zero, maximum values)
3. Error conditions (what happens with invalid input)
4. Any business rules documented in CLAUDE.md

Use Jest. Run the tests and make sure they all pass."

Integration tests

"Write integration tests that test the full sync flow end-to-end. Use a test database (not production).

The integration tests should:
1. Set up test data in the database
2. Run the sync process against our mock Shopify API
3. Verify the expected records were created/updated
4. Clean up test data afterward

Mock external APIs to avoid real API calls in tests."

Test coverage report

"Run the test suite with coverage enabled and show me the report. Then identify the 5 most important untested functions or paths and write tests for them. Prioritize by: business criticality first, then complexity."

The rule: Claude Code should never mark something “done” until its tests pass. If you enforce this discipline — “no next feature until this one has passing tests” — you’ll build software you can actually maintain.