All skills
mattpocock avatar

/tdd

@3216582 official
by Matt Pocockmattpocock/skills274k stars
22,991

Test-driven development. Use when the user wants to build features or fix bugs test-first, mentions "red-green-refactor", or wants integration tests.

Use this Skill: https://skilld.dev/gh/mattpocock/skills/tdd

This session only. Nothing lands on disk.

mocking.md

≈371 tokens on demand. Your agent reads this file only when SKILL.md points to it.

When to Mock

Mock at system boundaries only:

  • External APIs (payment, email, etc.)
  • Databases (sometimes - prefer test DB)
  • Time/randomness
  • File system (sometimes)

Don't mock:

  • Your own classes/modules
  • Internal collaborators
  • Anything you control

Designing for Mockability

At system boundaries, design interfaces that are easy to mock:

1. Use dependency injection

Pass external dependencies in rather than creating them internally:

// Easy to mock
function processPayment(order, paymentClient) {
  return paymentClient.charge(order.total);
}

// Hard to mock
function processPayment(order) {
  const client = new StripeClient(process.env.STRIPE_KEY);
  return client.charge(order.total);
}

2. Prefer SDK-style interfaces over generic fetchers

Create specific functions for each external operation instead of one generic function with conditional logic:

// GOOD: Each function is independently mockable
const api = {
  getUser: (id) => fetch(`/users/${id}`),
  getOrders: (userId) => fetch(`/users/${userId}/orders`),
  createOrder: (data) => fetch('/orders', { method: 'POST', body: data }),
};

// BAD: Mocking requires conditional logic inside the mock
const api = {
  fetch: (endpoint, options) => fetch(endpoint, options),
};

The SDK approach means:

  • Each mock returns one specific shape
  • No conditional logic in test setup
  • Easier to see which endpoints a test exercises
  • Type safety per endpoint

Source: SKILL.md on GitHub

No alerts2d5 checks · Risk SAFE
  • Gen Agent Trust Hub2d

    This skill provides best practices and guidelines for Test-Driven Development (TDD). It is purely informational and contains no malicious code, unauthorized network requests, or sensitive data exposure.

  • Socket2d

    No alerts

  • Snyk2d

    Risk: LOW · No issues

  • Runlayer7mo

    6 files scanned · No issues

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at 3216582. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 days ago.

Activeupdated 2 months ago

README badge

README badge for mattpocock/skills/tdd

Guides AI agents through test-driven development using vertical slices (one test, one implementation, repeat) rather than writing all tests upfront. Emphasizes integration-style tests that verify behavior through public interfaces and survive refactors, with a concrete workflow from planning through tracer bullets to incremental loops and refactoring.

Generated from the current SKILL.md.

Should I write all tests first, then all implementation?
No. Write one test, then implement to pass it, then repeat (vertical slices). Writing all tests upfront produces tests coupled to imagined behavior rather than actual behavior, and they won't catch real changes.
What kind of tests should I write?
Integration-style tests that exercise code through public APIs and verify observable behavior, not implementation details. Good tests read like specifications and survive refactors because they don't depend on internal structure.
Should I test private methods and internal functions?
No. Tests should only use public interfaces. If a test breaks when you refactor internal code without changing behavior, that test was testing implementation, not behavior.
Do I need to test every possible edge case?
No. Confirm with the user which behaviors are most important to test and focus effort on critical paths and complex logic rather than every edge case.

Generated from the current SKILL.md. These answers refresh after source changes.