Skip to content

commandTesting

Add Edge Case Tests

Adds tests for the boundary and error cases of one function: empty, huge, null, malformed and surprising input.

npx workspacetemplates add add-edge-case-tests --tool claude-code

Writes 1 file to .claude/commands/

.claude/commands/add-edge-case-tests.md14 lines · 1.3 KBFile
---
description: "Adds tests for the boundary and error cases of one function: empty, huge, null, malformed and surprising input."
argument-hint: "[function name or file:line]"
---

Add edge case tests for this function: $ARGUMENTS

1. Locate the function, its types or docstring, its callers and any existing tests. Note its contract: accepted input, return value, thrown errors.
2. List edge cases by category: empty (empty string, list, object), null or undefined, boundaries (0, 1, -1, max, max plus one), size (very long strings, 100k items), text (unicode, emoji, combining marks, newlines, leading and trailing whitespace), numbers (NaN, Infinity, floats like 0.1 + 0.2, very large integers), dates (leap day, DST change, timezone), type confusion, and repeated or concurrent calls.
3. Predict the expected result for each from the contract. Where the contract is silent, mark the case as a question rather than guessing.
4. Write the tests in the existing style, one behavior per test, with readable names. Use table-driven or parameterized tests where the framework supports them.
5. Run them. For any failure, decide if the function has a bug. Do not edit the function and do not weaken the test; list the bug.

Report tests added, passes, and bugs or open questions found. Ask how to resolve each.

What it does

Most functions are tested with three friendly examples. This command takes one function and probes its limits: what happens at zero, at the maximum, with missing values or with text that should not be there.

Where the function behaves badly, it reports the bug instead of baking it into the test, and asks how you want it to behave.

Example

you › /add-edge-case-tests parseDuration in src/lib/time.ts

agent › Added 26 cases in time.test.ts. 23 pass.
Bugs: parseDuration("") returns 0 instead of throwing; "1h30" silently ignores the missing unit; "99999999999d" overflows to a negative value.
Question: should "1.5h" be accepted?
How should the three bugs be handled?

Questions

Will it change the function when a test fails?
No. It reports the defect and asks which behavior you want first.
What if the contract is unclear?
Those cases are listed as questions so you decide the intended result before a test locks it in.
  • Add Regression Test

    CommandTesting

    Free
  • Coverage Gaps

    CommandTesting

    Free
  • E2E Scenario

    CommandTesting

    Free
  • Fix Failing Tests

    CommandTesting

    Free