agentleFS
int2t05int2t05/engineering-skills/skills/06-test/test-generation/SKILL.md

test-generation

Skill3 starsChanged 4 months agoMITView on GitHub

Use when generating test files for existing code or from a spec — language-agnostic, works with any test framework. Triggers on "generate tests", "write tests for", "生成测试", "生成测试代码", "补测试".

6 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

11 rules. 0 are common, 10 are distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 6 edited versions we read keep these.

  • 10

    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. Very specific:

    Ask for or discover: PRD path (default docs/PRD.md or docs/vX.Y/prd.md), architecture docs (default docs/TECH.md or docs/vX.Y/tech.md), …

    line 34
  2. Distinctive:

    Write anti-pattern-free test code to the correct test directories.

    line 60
  3. Distinctive:

    Every generated test file covers these dimensions:

    line 72
  4. Distinctive:

    When mock setup would exceed 50% of the test body (use an integration test)

    line 89
  5. Distinctive:

    When unsure of the dependency chain (run with real implementation first)

    line 90
  6. Distinctive:

    Completeness rule: when mocking an API response or data structure, include ALL fields the real implementation returns — not just the fields …

    line 92
  7. Distinctive:

    ALL fields the real implementation returns — not just the fields the immediate test touches.

    line 93
  8. Distinctive:

    Always generate integration tests alongside unit tests for features that span multiple components.

    line 98
  9. Distinctive:

    Use fewer (or zero) mocks — wire real components together

    line 101
  10. Distinctive:

    Verify the system behaves correctly end-to-end

    line 102
  11. Distinctive:

    Use language-idiomatic file naming

    line 103

“Common” is measured: kept by at least 6 in 10 of the 6 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

Test Generation (Language-Agnostic)

Generate anti-pattern-free test code from PRD acceptance criteria and source code. Read inputs, produce test files. No execution, no reports, no source modifications.

Input: PRD acceptance criteria + architecture docs + source code

When to use

  • Generating tests for a feature or bugfix
  • Creating tests from a PRD, API contract, or existing source
  • Triggers on "generate tests", "write tests for", "生成测试", "生成测试代码", "补测试"

Not for: the TDD red-green-refactor loop (use tdd); API contract testing (use api-testing); browser E2E flows (use e2e-testing).

Steps

1. Detect language & framework

Scan the project before generating. Detection priority: existing test files (naming conventions) → dependency manifests → test config files. If nothing found, ask which framework to use.

  • Load references/language-patterns.md for the per-language detection table (manifests and test-file patterns to scan for) and the Test Framework | Assertion Style | Mock Library mapping (testify/gomock, pytest/unittest.mock, jest/jest.fn, etc.)

2. Read inputs

Ask for or discover: PRD path (default docs/PRD.md or docs/vX.Y/prd.md), architecture docs (default docs/TECH.md or docs/vX.Y/tech.md), source code to test (default src/), and the auto-detected language/framework. Ask only critical questions before proceeding.

3. Extract testable conditions

  • Per acceptance criterion → one or more test cases
  • Per API endpoint / function signature → contract tests
  • Per defined error state → error path test
  • Per security-sensitive input → injection test (SQL, command, path traversal, XSS)
PRD: "US-001: User login"
AC: "Valid credentials return an authenticated session"
AC: "Invalid credentials return an error"
AC: "Empty fields show validation errors"

→ Test cases:
  1. valid credentials → success + session established
  2. wrong password → error response + message present
  3. empty email → validation error for email field
  4. empty password → validation error for password field

4. Generate test files

Write anti-pattern-free test code to the correct test directories. Every file starts with a comment linking to requirements:

// Generated from: docs/PRD.md, US-001: User login
// Acceptance criteria: valid login, invalid credentials, empty fields

Adapt the comment syntax to the language (#, //, /* */, --).

Coverage rules

Every generated test file covers these dimensions:

CategoryWhat to testAnti-pattern to avoid
Happy pathExpected input → expected outputDon't mock the function under test
ValidationInvalid/missing fields → proper errorsAssert real error, not mock call
Edge casesBoundary values, empty, null, very largeDon't mock out validation logic
Error statesTimeout, unavailable, 5xxMock at network/IO level, not error handler
SecurityInjection patterns, auth bypassTest real sanitization, not mock sanitizer

Mocking rules

Mock only at external boundaries: network, filesystem, clock, third-party APIs. Never mock:

  • The function/class under test itself
  • Internal helpers that are fast and side-effect-free
  • When mock setup would exceed 50% of the test body (use an integration test)
  • When unsure of the dependency chain (run with real implementation first)

Completeness rule: when mocking an API response or data structure, include ALL fields the real implementation returns — not just the fields the immediate test touches. Partial mocks hide structural assumptions and fail silently.

Integration tests are not optional

Always generate integration tests alongside unit tests for features that span multiple components. Integration tests:

  • Use fewer (or zero) mocks — wire real components together
  • Verify the system behaves correctly end-to-end
  • Use language-idiomatic file naming
Source: src/auth/login.go
  → Unit: src/auth/login_test.go
  → Integration: tests/integration/auth_login_test.go

Generator decision matrix

Input hasGenerate
User story + ACUnit tests per AC + integration test for the story
API contract + schemaContract / integration tests per endpoint
Source code without ACUnit tests for public API surface
Error states in contractError path tests covering every defined error
Security-sensitive inputsInjection tests (SQL, command, path traversal, XSS)
Database operationsTransaction/rollback tests
Auth-protected endpointsUnauthenticated + forbidden tests

Output: Complete test files (unit + integration) — code, not a report.

Verify

  • Language and framework auto-detected (not defaulted blindly)
  • Every acceptance criterion has a matching test case
  • Happy path, validation, edge cases, and error states covered per feature
  • Both unit AND integration tests generated for multi-component features
  • Mocks mirror the complete real data structure — no partial mocks
  • Every test file has a source comment linking to requirements
  • No test-only methods added to production classes
  • No assertions solely on mock behavior or call counts

References

  • ${CLAUDE_PLUGIN_ROOT}/references/engineering-principles.md — discipline every skill shares
  • ${CLAUDE_PLUGIN_ROOT}/references/clean-code.md — clean code principles for test quality
  • references/language-patterns.md — per-language Test Framework | Assertion Style | Mock Library mapping

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.