TDD Guide

Guides test-driven development: writing unit tests, generating fixtures and mocks, analyzing coverage gaps, and running red-green-refactor cycles across Jest, Pytest.

Development / Engineeringdevelopmentengineering
by AgentVoltv1.0.0Published 1y ago2 installs
Free to sign up · every skill included with AgentVolt Pro

Before & after

Same prompt, same agent — the only difference is the skill.

PromptWrite unit tests for our authentication module following TDD.
Beforegeneric AI agent
Test-driven development means you write tests first, then write code to pass them. For an auth module, you'd think about the different scenarios: valid credentials should authenticate the user, invalid credentials should fail, expired tokens should be rejected, etc. You'd write test code that covers these scenarios. Then you write the actual implementation. Tests need to cover the happy path and error cases. You might also use mocks for external dependencies like a database. Good test coverage helps catch bugs early and makes refactoring safer.
Afterwith TDD Guide
I'll guide you through TDD for your auth module, from test definition through red-green-refactor cycles.

RED-GREEN-REFACTOR WORKFLOW
RED PHASE (Write failing test first)
Identify a single behavior: "authenticate should return a token for valid credentials"
Write a test that calls your auth function with known-valid inputs and asserts the output:
it("returns JWT token for valid username/password") {
  const token = authenticate("user@example.com", "password123");
  expect(token).toBeDefined();
  expect(token.startsWith("eyJ")).toBe(true);
}
Run test -> RED (fails because authenticate() doesn't exist yet).

GREEN PHASE (Write minimal code to pass)
Implement only what's needed to pass:
function authenticate(email, password) {
  return "eyJhbGciOiJIUzI1NiJ9...";
}
Run test -> GREEN (passes).

REFACTOR PHASE (Improve without breaking tests)
Strengthen the implementation: add credential validation, real JWT signing, error handling. Tests confirm each change doesn't break behavior.

TEST CASES FOR AUTH MODULE
Valid credentials: token returned, token contains email claim, token has expiry
Invalid password: AuthError thrown with "invalid credentials" message
User not found: AuthError thrown with "user not found" message
Expired token: verify() rejects with "token expired"
Malformed token: verify() rejects
Token revocation: revoked tokens don't authenticate

MOCKING STRATEGY
Mock database: pass a mock DB to auth() instead of real queries. Test returns correct error when DB fails.
Mock clock: test token expiry by advancing time (jest.useFakeTimers).

DELIVERABLE
Test file with 8-10 test cases covering happy path + all error scenarios. Implementation grows incrementally to pass each test.

About this skill


name: tdd-guide description: Use when Test-driven development skill for writing unit tests, generating test fixtures and mocks, analyzing coverage gaps, and guiding red-green-refactor workflows across Jest, Pytest, JUnit, Vitest, and M...

Tdd Guide

Test-driven development skill for writing unit tests, generating test fixtures and mocks, analyzing coverage gaps, and guiding red-green-refactor workflows across Jest, Pytest, JUnit, Vitest, and Mocha. Use when the user asks to write tests, improve test coverage, practice TDD, generate mocks or stubs, or mentions testing frameworks like Jest, pytest, or JUnit.

What you get

  • Public GitHub repo (alirezarezvani/claude-skills)
  • the tdd-guide skill folder with SKILL.md. Part of a 337-skill / 30-agent / 70-command install.

Customize your output

  • Fork the repo and adapt the skill's instructions and references to your workflow.

Example output

Activates automatically when your request matches Tdd Guide; chains with the other skills, agents, and commands in the collection.

Best for

Creators, builders, and teams using Claude Code.

SKILL.md preview

SKILL.md
---
name: tdd-guide
description: Use when the user asks to write tests, improve test coverage, practice test-driven development, generate mocks or stubs, or mentions testing frameworks like Jest, pytest, or JUnit.
version: 1.0.0
category: Development / Engineering
author: AgentVolt
license: proprietary
tags:
  - development
  - engineering
---

# Tdd Guide

Guides test-driven development: writing unit tests, generating fixtures and mocks, analyzing coverage gaps, and running red-green-refactor cycles across Jest, Pytest, JUnit, Vitest, and Mocha.

## When to use

… (sign up to view the full skill)
Sign up to view, copy, and install the full skill

More development skills

View all Development skills →