agentleFS
jamestorrevillasjamestorrevillas/dev-skills/.github/skills/testing/SKILL.md

testing

Skill4 starsChanged 9 months agoMITView on GitHub

Use this skill when writing or improving tests of any kind — unit tests, integration tests, end-to-end (E2E) tests, API tests, or test coverage analysis. Trigger on keywords: test, spec, unit test, integration test, E2E, Playwright, Jest, Vitest, pytest, mock, coverage, TDD, test suite, assertion.

194 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use bundle-dependency-prs, update-library-template 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.
  • MicrosoftSkill

    bundle-dependency-prs

    Fix broken dependency update PRs and aggregate the ones that work into one PR.

    Also in 8 projects that use this

  • MicrosoftSkill

    update-library-template

    Merges the latest Library.Template into this repo (at position of HEAD) and resolves conflicts.

    Also in 8 projects that use this

  • NVIDIA-NeMoSkill

    build-and-dependency

    Dev environment setup for Megatron Bridge — container-based development, uv package management, lockfile regeneration, adding dependencies, Slurm container usage, and common build pitfalls.

    Also in 3 projects that use this

  • timmo001Skill

    changeset-scope

    Keep all scoped code work contained to the user-defined changeset. Use for implementation, fixes, diagnosis, refactoring, cleanup, and review when explicit instructions, named files, diffs, branches, pull requests, or injected work scopes define the boundary.

    Also in 3 projects that use this

  • JetBrainsSkill

    module-dependencies

    Add or modify IntelliJ module dependencies in `.iml` files.

    Also in 3 projects that use this

  • CES-LtdSkill

    oss-pr

    Use when creating a pull request, after committing changes, or when user invokes /oss-pr. Covers branch management, quality checks, commit, push, and PR creation.

    Also in 3 projects that use this

The file

We split this skill into the rules it gives an agent

12 rules. 0 are common, 12 are distinctive, and 0 are very specific to this project.

  • 0

    Common

    Most of the 175 edited versions we read keep these.

  • 12

    Distinctive

    This author's own choices. Worth a look.

  • 0

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    The Verify Output Principle: Every piece of AI-generated code should pass through an AI-generated but human-reviewed test suite before …

    line 12
  2. Distinctive:

    Test behavior, not implementation details

    line 37
  3. Distinctive:

    Use the AAA pattern: Arrange → Act → Assert

    line 39
  4. Distinctive:

    Test edge cases: null, empty, boundary values, error paths

    line 41
  5. Distinctive:

    Test the contract between components, not their internals

    line 75
  6. Distinctive:

    Use a real (but isolated) database — not mocks

    line 76
  7. Distinctive:

    Test API endpoints with realistic payloads

    line 78
  8. Distinctive:

    Test request/response contracts

    line 96
  9. Distinctive:

    Test authentication and authorization flows

    line 97
  10. Distinctive:

    Test pagination and filtering

    line 99
  11. Distinctive:

    Use Playwright for E2E testing — it supports all major browsers, has auto-wait built in, and works well with AI agent verification.

    line 106
  12. Distinctive:

    Always mock external API calls in unit/integration tests:

    line 151

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

Core Philosophy

AI-generated code is untrusted until it passes a human-reviewed test suite. Tests are not optional — they are the safety net that makes refactoring and agentic code generation safe. Treat test code with the same quality standards as production code.

The Verify Output Principle: Every piece of AI-generated code should pass through an AI-generated but human-reviewed test suite before being considered complete.


Test Pyramid

        /\
       /E2E\          ← Few, slow, high confidence
      /------\
     /Integr. \       ← Some, medium speed
    /------------\
   /   Unit Tests  \  ← Many, fast, isolated
  /------------------\
  • Unit tests — 70% of your suite. Fast, isolated, no external dependencies.
  • Integration tests — 20%. Test how components work together.
  • E2E tests — 10%. Test real user flows from browser to DB.

Unit Testing

Principles

  • Test behavior, not implementation details
  • One assertion concept per test
  • Use the AAA pattern: Arrange → Act → Assert
  • Mock all external dependencies (APIs, databases, file system)
  • Test edge cases: null, empty, boundary values, error paths

Structure

describe('ComponentOrFunction', () => {
  describe('methodName', () => {
    it('should [expected behavior] when [condition]', () => {
      // Arrange
      const input = ...

      // Act
      const result = functionUnderTest(input)

      // Assert
      expect(result).toBe(expectedValue)
    })
  })
})

What to Test

ScenarioPriority
Happy path (expected behavior)Must have
Edge cases (null, empty, boundary)Must have
Error paths (exceptions, failures)Must have
Invalid inputsMust have
Performance-critical pathsNice to have

Integration Testing

Integration Principles

  • Test the contract between components, not their internals
  • Use a real (but isolated) database — not mocks
  • Clean up test data after each test
  • Test API endpoints with realistic payloads

Database Integration Tests

# Python example
def test_create_user_persists_to_db(db_session):
    # Arrange
    user_data = {"name": "James", "email": "james@test.com"}

    # Act
    user = create_user(db_session, user_data)

    # Assert
    saved = db_session.query(User).filter_by(id=user.id).first()
    assert saved.email == "james@test.com"

API Integration Tests

  • Test request/response contracts
  • Test authentication and authorization flows
  • Test error responses (400, 401, 403, 404, 500)
  • Test pagination and filtering

End-to-End (E2E) Testing

Tool Recommendation

Use Playwright for E2E testing — it supports all major browsers, has auto-wait built in, and works well with AI agent verification.

Selector Priority (Most to Least Robust)

  1. getByRole() — ARIA roles (most resilient)
  2. getByText() — visible text
  3. getByTestId() — data-testid attributes
  4. getByLabel() — form labels
  5. CSS selectors — (avoid, brittle)

E2E Test Structure

test('user can complete checkout flow', async ({ page }) => {
  // Navigate
  await page.goto('/products')

  // Interact
  await page.getByRole('button', { name: 'Add to Cart' }).first().click()
  await page.getByRole('link', { name: 'Checkout' }).click()

  // Fill form
  await page.getByLabel('Email').fill('test@example.com')

  // Assert
  await expect(page.getByText('Order confirmed')).toBeVisible()
})

What to Cover with E2E

  • Critical user journeys (signup, login, core feature flows)
  • Payment or checkout flows
  • Authentication flows (login, logout, password reset)
  • Error states visible to users

Mocking & Test Doubles

TypeWhen to Use
MockVerify a function was called with specific arguments
StubReplace a function with a fixed return value
SpyObserve calls without replacing behavior
FakeLightweight working implementation (e.g., in-memory DB)

Mock External APIs

Always mock external API calls in unit/integration tests:

jest.mock('../services/paymentService', () => ({
  chargeCard: jest.fn().mockResolvedValue({ success: true })
}))

Test Coverage Guidelines

Coverage LevelMeaning
< 60%Dangerous — high risk of regressions
60–80%Acceptable for early-stage projects
80–90%Good — production ready
90–95%Excellent
> 95%Diminishing returns — focus on quality not quantity

Coverage doesn't equal quality. 95% coverage with weak assertions is worse than 80% coverage with strong assertions.


Testing AI-Generated Code

  1. Generate tests before or alongside the code — don't test after
  2. Review AI-generated tests critically — they often miss edge cases
  3. Add tests for every bug found — regression coverage
  4. Test the behavior described in the spec, not just what the code does
  5. Mutation testing — use tools like Stryker to verify tests actually catch bugs

Framework Quick Reference

LanguageUnitIntegrationE2E
TypeScript/JSJest / VitestSupertest + JestPlaywright
Pythonpytestpytest + SQLAlchemyPlaywright
JavaJUnit 5Spring Boot TestPlaywright

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.