agentleFS
dafaalzdafaalz/agent-skills/skills/testing-patterns/SKILL.md

testing-patterns

Skill2 starsChanged 2 months agoMITView on GitHub

Use when writing automated tests, creating test fixtures, configuring test mocks or testcontainers, implementing contract tests, or refactoring test suites. Don't use for manual QA testing plans, load testing scripts, or visual regression screenshot testing.

  • Deletes or force-pushes

24 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use intelligent-routing, api-patterns 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.
  • tiendatworkSkill

    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 3 projects that use this

  • xfstudioSkill

    api-patterns

    API design principles and decision-making. REST vs GraphQL vs tRPC selection, response formats, versioning, pagination.

    Also in 5 projects that use this

  • xfstudioSkill

    rust-pro

    Master Rust 1.75+ with modern async patterns, advanced type system

    Also in 3 projects that use this

  • benshapyroSkill

    documentation-templates

    Generates README files, API documentation, and inline code comments following best practices. Use when creating project documentation, writing READMEs, documenting APIs, or explaining complex code.

    Also in 3 projects that use this

  • +8 more from xfstudio

The file

We split this skill into the rules it gives an agent

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

  • 0

    Common

    Most of the 17 edited versions we read keep these.

  • 6

    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:

    Read the reference guides for domain-specific execution details:

    line 10
  2. Distinctive:

    Run real database instances in ephemeral containers using Testcontainers instead of using in-memory SQL emulators like SQLite or H2.

    line 71
  3. Distinctive:

    Verify schema agreements using consumer-driven contracts with Pact instead of running live downstream services.

    line 75
  4. Distinctive:

    Test components and services as black boxes:

    line 83
  5. Very specific:

    Use getByTestId only as a fallback for non-semantic canvas controls or complex custom graphics.

    line 88
  6. Distinctive:

    Use web-first assertions for asynchronous interfaces:

    line 89
  7. Distinctive:

    Verify test execution speed, determinism, and absence of intermittent failures:

    line 97

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

Build deterministic, architecture-aligned test suites with clear network boundaries, isolated fixtures, and declarative assertions across frontend, backend, and browser layers.

Read the reference guides for domain-specific execution details:

  • For frontend web interfaces, component trees, and accessibility auditing, read references/frontend-patterns.md.
  • For backend services, containerized databases, API contracts, and property fuzzing, read references/backend-patterns.md.
  • For browser user journeys, Playwright locators, and session reuse, read references/e2e-patterns.md.
  • For test fixture generation, fluent builders, and tenant isolation, read references/test-data-builders.md.
  • For seam boundary and mock isolation pitfalls, read references/tdd-anti-patterns.md.
  • For pre-commit gates, Husky setup, and lint-staged automation, read references/pre-commit-hooks.md.
  • For boundary value analysis, equivalence partitioning, and exploratory test charters, read references/test-matrix-and-charters.md.

Workflow

Execute the six testing steps sequentially. Complete each verification criterion before proceeding to the next step.

Step 1. Red-green loop and seam selection

Apply test-driven development through vertical slices at confirmed seam boundaries:

  1. Identify candidate public seams:
    • Inspect the caller contract or public interface specification.
    • Target public methods, API endpoints, or top-level component boundaries. Avoid reaching into private collaborators or internal state.
    • Consult references/tdd-anti-patterns.md for seam boundary and mock isolation pitfalls.
  2. Execute the Red-green loop per vertical slice:
    • Red. Write a minimal failing test observing behavior at the public seam. Run the test to confirm it fails cleanly from missing behavior rather than syntax or setup errors.
    • Green. Write minimal production code to pass the test without premature optimization, unused configurability, or speculative abstractions. Run the test suite to confirm clean passes.
    • Refactor. Clean up structure, remove duplication, and improve readability only after tests pass.
    • Repeat the loop for subsequent vertical slices.

Completion criterion. Target seams map to public contracts, and every slice passes through verified red-green cycles before refactoring.

Step 2. Scope and tier selection

Align testing scope with system topology to prevent duplicated test coverage:

  1. Choose the distribution model matching target architecture:
    • Testing Trophy for web applications and client components. Concentrate coverage on integration tests while keeping unit tests restricted to pure functions and state machines.
    • Testing Pyramid for backend monoliths with rich domain rules. Anchor the base with fast domain unit tests, intermediate service tests, and a small apex of end-to-end journeys.
    • Testing Honeycomb for microservices and event systems. Focus on service-level integration tests, Pact boundary contracts, and minimal integrated flows.
  2. For browser suites, limit scope to Tier 1 business journeys whose failure blocks revenue or authentication. Delegate secondary validations, form errors, and edge layouts to component integration suites.

Completion criterion. The testing tier matches system architecture, and test scope excludes redundant coverage across tiers.

Step 3. Test data strategy via test data builders

Construct fixtures through fluent test data builders following Google DAMP (Descriptive And Meaningful Phrases) principles:

  1. Replace static JSON dumps and raw SQL scripts with fluent builders to keep test intent visible.
  2. Encapsulate valid default attributes within builders. Calling build() without arguments must yield a valid, persistable entity.
  3. Chain override methods such as withStatus() or withTier() to declare only attributes required by the specific test.
  4. Inject sequential counters or random identifiers into emails, primary keys, and tenant identifiers to maintain test isolation during parallel execution.

Completion criterion. Tests construct domain fixtures through fluent builders, declaring only fields required for the test scenario while running deterministically in parallel.

Step 4. Network and dependency isolation

Isolate network boundaries and infrastructure dependencies through environment-native interception:

  1. For frontend component and integration tests:
    • Intercept HTTP requests at the transport boundary using Mock Service Worker (MSW v2) instead of monkey-patching global.fetch or Axios instances.
    • Configure lifecycle hooks to start MSW before tests, reset handlers after every test, and close the server on teardown.
    • Set MSW to throw errors on unhandled requests to detect missing mock endpoints.
  2. For backend persistence tests:
    • Run real database instances in ephemeral containers using Testcontainers instead of using in-memory SQL emulators like SQLite or H2.
    • Mount database storage directories onto in-memory filesystems (tmpfs) to eliminate disk write latency.
    • Share a singleton container instance across test files and truncate tables with cascading resets between tests.
  3. For distributed microservice boundaries:
    • Verify schema agreements using consumer-driven contracts with Pact instead of running live downstream services.

Completion criterion. Network calls intercept cleanly through MSW, and backend persistence tests execute against containerized databases on tmpfs mounts.

Step 5. Declarative assertion construction

Construct assertions evaluating public observable behavior and accessibility trees instead of internal implementation details:

  1. Test components and services as black boxes:
    • Assert on observable DOM output, HTTP responses, and database state instead of internal state variables or private methods.
    • Reserve call count verification strictly for external side-effect boundaries like payment gateways or email dispatchers.
  2. Locate user interface elements through the accessibility tree:
    • Query elements following the priority order of getByRole, getByLabelText, getByPlaceholderText, and getByText.
    • Use getByTestId only as a fallback for non-semantic canvas controls or complex custom graphics. Avoid querying by CSS classes, HTML tags, or XPath selectors.
  3. Use web-first assertions for asynchronous interfaces:
    • Assert using auto-waiting matchers like expect(locator).toBeVisible() or expect(locator).toHaveText() that poll the DOM until conditions settle.
    • Pair element checks with auto-waiting assertions instead of executing immediate assertions against static snapshots.

Completion criterion. Assertions verify only public behavior, accessible roles, or persisted state without inspecting internal implementation mechanics.

Step 6. Speed and determinism verification

Verify test execution speed, determinism, and absence of intermittent failures:

  1. Meet latency budgets:
    • Domain unit tests complete within sub-millisecond durations per test case.
    • Integration tests complete within sub-second durations per test case using tmpfs and connection reuse.
    • Browser end-to-end journeys complete within 10 to 30 seconds per journey.
  2. Eliminate flakiness sources:
    • Replace arbitrary sleep calls like sleep() or waitForTimeout() with explicit assertions on visible UI states or resolved network promises.
    • Replace page.waitForLoadState('networkidle') with explicit element locators or backend response listeners.
    • Inject pre-authenticated storageState JSON files into browser contexts instead of executing repetitive UI logins.
  3. Execute the full test suite three consecutive times across multiple worker processes without failures.

Completion criterion. The suite passes three consecutive parallel test runs with zero arbitrary sleeps and within established latency budgets.

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.