agentleFS
edjchapmanedjchapman/claude-code-config/skills/testing-patterns/SKILL.md

testing-patterns

Skill8 starsChanged 19 days agoMITView on GitHub

Test structure, fixtures, factories, and mocking conventions. Use when writing or reviewing tests, or files named test_*, *_test, *.test.*, or *.spec.*.

44 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use intelligent-routing, bash-linux and 10 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • SKB3002Skill

    intelligent-routing

    Automatic agent selection and intelligent task routing. Analyzes user requests and automatically selects the best specialist agent(s) without requiring explicit user mentions.

    Also in 5 projects that use this

  • xenitV1Skill

    bash-linux

    Bash/Linux terminal patterns. Critical commands, piping, error handling, scripting. Use when working on macOS or Linux systems.

    Also in 6 projects that use this

  • xenitV1Skill

    red-team-tactics

    Red team tactics principles based on MITRE ATT&CK. Attack phases, detection evasion, reporting.

    Also in 6 projects that use this

  • ChrisWilesSkill

    formik-patterns

    Formik form handling with validation patterns. Use when building forms, implementing validation, or handling form submission.

    Also in 3 projects that use this

  • SKB3002Skill

    nextjs-react-expert

    React and Next.js performance optimization from Vercel Engineering. Use when building React components, optimizing performance, eliminating waterfalls, reducing bundle size, reviewing code for performance issues, or implementing server/client-side optimizations.

    Also in 3 projects that use this

  • adybaSkill

    safe-workflow

    SAFe Agentic Workflow orchestrator. Teaches the full SAFe methodology adapted for AI agents: pattern discovery, exit states, quality gates, agent personas, and specs-driven development. Use when setting up a project with SAFe workflow, understanding the multi-agent methodology, or coordinating work across agent personas. Triggers: "SAFe workflow", "agent workflow", "safe harness", "specs-driven", "exit states", "quality gates", "multi-agent workflow".

    Also in 3 projects that use this

  • +4 more from xenitV1

The file

We split this skill into the rules it gives an agent

8 rules. 0 are common, 7 are distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 29 edited versions we read keep these.

  • 7

    Distinctive

    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:

    Every test should follow the AAA pattern with clear visual separation:

    line 12
  2. Distinctive:

    Test names should describe the scenario and expected outcome:

    line 43
  3. Distinctive:

    Never hardcode IDs or timestamps -- use factories to generate them

    line 57
  4. Very specific:

    Use fresh database transactions per test (Django: TestCase with automatic rollback)

    line 63
  5. Distinctive:

    Don't chase 100% -- focus on meaningful assertions over line coverage

    line 85
  6. Distinctive:

    Prefer dependency injection over patching

    line 90
  7. Distinctive:

    Verify mock interactions only when the side effect IS the behavior

    line 91
  8. Distinctive:

    Don't mock the thing you're testing

    line 92

“Common” is measured: kept by at least 6 in 10 of the 29 edited versions of this file we could read. “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

Testing Patterns

Apply these patterns when writing or reviewing tests.

Structure: Arrange-Act-Assert (AAA)

Every test should follow the AAA pattern with clear visual separation:

def test_user_creation_with_valid_data():
    # Arrange
    user_data = {"email": "test@example.com", "name": "Test User"}

    # Act
    user = UserService.create(user_data)

    # Assert
    assert user.email == "test@example.com"
    assert user.is_active is True
it("creates a user with valid data", () => {
  // Arrange
  const userData = { email: "test@example.com", name: "Test User" };

  // Act
  const user = UserService.create(userData);

  // Assert
  expect(user.email).toBe("test@example.com");
  expect(user.isActive).toBe(true);
});

Naming Convention

Test names should describe the scenario and expected outcome:

  • Python: test_<unit>_<scenario>_<expected_result>
  • TypeScript: "<unit> <scenario> <expected result>"

Good: test_login_with_invalid_password_returns_401 Bad: test_login, test_case_1

Test Data

Use Factories (not fixtures for mutable data)

  • Python: factory_boy or custom factory functions
  • TypeScript: builder pattern or factory functions
  • Never hardcode IDs or timestamps -- use factories to generate them
  • Share setup via factory defaults, override per-test as needed

Isolation

  • Each test must be independent -- no shared mutable state
  • Use fresh database transactions per test (Django: TestCase with automatic rollback)
  • Mock external services at the boundary (HTTP, email, queues)

What to Test

Must Test

  • Happy path for every public function/endpoint
  • Error/edge cases: null inputs, empty collections, boundary values
  • Authorization: ensure protected routes reject unauthorized access
  • Validation: verify invalid input is rejected with correct errors

Don't Test

  • Private/internal methods directly (test through public interface)
  • Framework code (Django ORM, React rendering engine)
  • Trivial getters/setters with no logic

Coverage Expectations

  • New code: aim for 80%+ line coverage
  • Critical paths (auth, payments, data mutations): 95%+
  • Don't chase 100% -- focus on meaningful assertions over line coverage

Mocking Guidelines

  • Mock at boundaries: HTTP clients, databases, file systems, clocks
  • Prefer dependency injection over patching
  • Verify mock interactions only when the side effect IS the behavior
  • Don't mock the thing you're testing

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.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

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.