Workflow Testing

Write Unit Tests

Workflow for writing effective unit tests for a function or module

testingunit-testsdevelopment
CLAUDE.md

When writing unit tests for a function or module:

  1. Identify the public API — the functions and methods that consumers call.
  2. For each public function, list the behaviors to test: normal cases, edge cases, error cases.
  3. Write a test for the most common usage first (the happy path).
  4. Add edge case tests: empty input, null, zero, negative numbers, very large inputs, special characters.
  5. Add error case tests: invalid input, missing required fields, network failures.
  6. Name each test to describe the expected behavior, not the implementation.
  7. Use arrange-act-assert structure: set up data, call the function, check the result.
  8. Run the tests to confirm they pass. Then break the implementation to confirm they catch real failures.

Copy this workflow into your CLAUDE.md or agent config file so your agent follows this process automatically.

get crystl