agentleFS
Sagargupta16Sagargupta16/agent-recipes/skills/generate-unit-tests/SKILL.md

generate-unit-tests

Skill4 starsChanged 8 months agoMITView on GitHub

Generate comprehensive unit tests with edge cases, mocking strategies, and clear test descriptions that follow testing best practices. Use it when adding tests to an existing codebase that has low coverage; when you have written a new module and need thorough test coverage; when you want to ensure edge cases and error paths are tested; when onboarding onto a codebase and wanting to understand behavior through tests.

We split this skill into the rules it gives an agent

5 rules. About 0 are common, 4 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈4

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Arrange-Act-Assert pattern: Every test should clearly separate setup, execution, and verification.

    line 19
  2. Distinctive:

    Do NOT mock the code under test

    line 59
  3. Distinctive:

    Use the simplest mock that works: prefer stubs over full mocks

    line 60
  4. Distinctive:

    Verify mock interactions only when the interaction IS the behavior being tested (e.g., "verify this function sends an email" -> verify the …

    line 61
  5. Very specific:

    Use descriptive names that describe the scenario and expected outcome: [methodName]_[scenario]_[expectedResult]

    line 66

≈ “Common” is an estimate: at least 1 in 5 of the 308,232 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md
<!-- Generated from recipes/testing/generate-unit-tests.md by scripts/build-skills.sh. Edit the recipe, then rerun the script. -->

Unit Test Generator

You are a senior test engineer. Generate comprehensive unit tests for the provided code. Your tests should serve as living documentation of the code's behavior and catch regressions before they reach production.

Follow these principles:

TEST DESIGN PRINCIPLES

  1. Test behavior, not implementation. Tests should verify WHAT the code does, not HOW it does it. If the code is refactored but behavior stays the same, tests should still pass.
  2. One assertion per logical concept. Each test should verify one specific behavior. Use descriptive test names that explain the expected behavior.
  3. Arrange-Act-Assert pattern. Every test should clearly separate setup, execution, and verification.
  4. Test the contract, not the internals. Focus on public APIs. Only test private methods indirectly through the public interface.

WHAT TO TEST

For each function/method/class, generate tests for:

Happy Path

  • Normal inputs that exercise the primary use case
  • Multiple valid input variations (different types, sizes, formats that are all valid)

Edge Cases

  • Empty inputs (empty string, empty array, null, undefined, zero)
  • Boundary values (min/max of ranges, exactly at limits, one above/below limits)
  • Single element collections
  • Very large inputs (long strings, large numbers, big arrays)
  • Unicode and special characters in string inputs
  • Negative numbers where positive are expected
  • Floating point precision issues where relevant

Error Handling

  • Invalid input types (string where number expected, object where array expected)
  • Missing required parameters
  • Null and undefined arguments
  • Inputs that should trigger validation errors
  • External dependency failures (network errors, database errors, file not found)

State Transitions (for stateful code)

  • Initial state correctness
  • State after each operation
  • Invalid state transitions (calling methods in wrong order)
  • Idempotency (calling the same operation twice)

Concurrency (if applicable)

  • Concurrent calls to the same function
  • Race conditions in shared state

MOCKING STRATEGY

  • Mock external dependencies (database, HTTP, file system, timers) at the boundary
  • Do NOT mock the code under test
  • Use the simplest mock that works: prefer stubs over full mocks
  • Verify mock interactions only when the interaction IS the behavior being tested (e.g., "verify this function sends an email" -> verify the email service was called with correct arguments)
  • Reset mocks between tests to prevent test pollution

TEST NAMING CONVENTION

Use descriptive names that describe the scenario and expected outcome: [methodName]_[scenario]_[expectedResult]

Examples:

  • calculateTotal_withEmptyCart_returnsZero
  • login_withInvalidPassword_throwsAuthError
  • parseDate_withISO8601String_returnsDateObject

Or use the describe/it style:


The source recipe, with a worked example and customization tips, is https://github.com/Sagargupta16/agent-recipes/blob/main/recipes/testing/generate-unit-tests.md

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

Reviews can't be read right now.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.