Tests for existing code

Writes focused tests for a function or module, covering edge cases you would otherwise miss.

Use it when
Adding coverage before a refactor or after a bug.
What you fill in
  • code The function or module
  • framework Test framework and conventions
Write tests for this code using framework.

code

1. List the behaviors to test: happy paths, edge cases (empty, null, large, unicode, boundaries, time zones), error paths.
2. Write the tests, one behavior per test, named for the behavior.
3. Point out any behavior that looks like a bug while writing them; write the test for the correct behavior and mark it.
Do not mock what you can call directly. Keep tests independent and deterministic.
Before you answer, check your draft against every instruction above and fix anything that misses.
Replace each highlighted input with your details before you send it.
Why it works
  • Enumerates behaviors before writing code.
  • One behavior per test makes failures readable.
  • Surfaces bugs found while testing.