Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

Test-Driven Development (TDD)

БесплатноБез исполняемых скриптовНе проверен

Master the Test-Driven Development approach with Red-Green-Refactor cycles, writing tests before code, comprehensive coverage patterns, and quality code…

PramodDuttaот PramodDutta★ 253 звезды на GitHub

Об этом скилле

Test-Driven Development (TDD) Skill

You are an expert in Test-Driven Development (TDD), a software development approach where tests are written before the code they validate. When the user asks you to implement features using TDD, write tests, or refactor code, follow these detailed instructions.

Core Principles

  1. Red-Green-Refactor cycle -- Write failing test (Red) → Make it pass (Green) → Improve code (Refactor).
  2. Test-first mindset -- Never write production code without a failing test demanding it.
  3. Small increments -- Take tiny steps, writing minimal code to pass each test.
  4. Continuous refactoring -- Keep code clean through constant small improvements.
  5. Fast feedback -- Tests must run quickly to maintain development flow.

The TDD Cycle

Red Phase: Write a Failing Test

Write the smallest test that specifies the next bit of functionality.

// Example: Calculator addition feature
describe('Calculator', () => {
  it('should add two positive numbers', () => {
    const calculator = new Calculator();
    expect(calculator.add(2, 3)).toBe(5);
  });
});

Run the test → It should fail (Red) because Calculator doesn't exist yet.

Green Phase: Make It Pass

Write the minimal code to make the test pass. Don't worry about perfection.

class Calculator {
  add(a: number, b: number): number {
    return 5; // Hardcoded to make test pass
  }
}

Run the test → It should pass (Green).

Refactor Phase: Improve the Code

Now make the code better while keeping tests green.

class Calculator {
  add(a: number, b: number): number {
    return a + b; // Proper implementation
  }
}

Run the test → Still passes. Safe to refactor.

Repeat: Add More Tests

describe('Calculator', () => {
  it('should add two positive numbers', () => {
    const calculator = new Calculator();
    expect(calculator.add(2, 3)).toBe(5);
  });

  it('should add negative numbers', () => {
    const calculator = new Calculator();
    expect(calculator.add(-2, -3)).toBe(-5);
  });

  it('should add zero', () => {
    const calculator = new Calculator();
    expect(calculator.add(5, 0)).toBe(5);
  });
});

TDD in Different Languages

JavaScript/TypeScript with Jest/Vitest

// tests/user-service.test.ts
import { UserService } from '../src/user-service';
import { User } from '../src/types';

describe('UserService', () => {
  let userService: UserService;

  beforeEach(() => {
    userService = new UserService();
  });

  describe('createUser', () => {
    it('should create a user with valid data', () => {
      const userData = {
        email: '[email protected]',
        name: 'John Doe',
        age: 30,
      };

      const user = userService.createUser(userData);

      expect(user.id).toBeDefined();
      expect(user.email).toBe('[email protected]');
      expect(user.name).toBe('John Doe');
      expect(user.createdAt).toBeInstanceOf(Date);
    });

    it('should throw error for invalid email', () => {
      const userData = {
        email: 'invalid-email',
        name: 'John Doe',
        age: 30,
      };

      expect(() => userService.createUser(userData)).toThrow('Invalid email format');
    });

    it('should throw error for age below 18', () => {
      const userData = {
        email: '[email protected]',
        name: 'Young User',
        age: 15,
      };

      expect(() => userService.createUser(userData)).toThrow('User must be at least 18 years old');
    });
  });

  describe('getUserById', () => {
    it('should return user when found', () => {
      const createdUser = userService.createUser({
        email: '[email protected]',
        name: 'John Doe',
        age: 30,
      });

      const foundUser = userService.getUserById(createdUser.id);

      expect(foundUser).toEqual(createdUser);
    });

    it('should return null when user not found', () => {
      const user = userService.getUserById('non-existent-id');

      expect(user).toBeNull();
    });
  });

  describe('updateUser', () => {
    it('should update user fields', () => {
      const user = userService.createUser({
        email: '[email protected]',
        name: 'John Doe',
        age: 30,
      });

      const updated = userService.updateUser(user.id, {
        name: 'Jane Doe',
        age: 31,
      });

      expect(updated.name).toBe('Jane Doe');
      expect(updated.age).toBe(31);
      expect(updated.email).toBe('[email protected]'); // Unchanged
    });

    it('should throw error when updating non-existent user', () => {
      expect(() =>
        userService.updateUser('non-existent-id', { name: 'New Name' })
      ).toThrow('User not found');
    });
  });

  describe('deleteUser', () => {
    it('should delete user and return true', () => {
      const user = userService.createUser({
        email: '[email protected]',
        name: 'John Doe',
        age: 30,
      });

      const deleted
Полный SKILL.md на GitHub

Установить Test-Driven Development (TDD) в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

FAQ

Что делает скилл Test-Driven Development (TDD)?

Master the Test-Driven Development approach with Red-Green-Refactor cycles, writing tests before code, comprehensive coverage patterns, and quality code practices for building robust, maintainable software.

Как установить скилл Test-Driven Development (TDD)?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл Test-Driven Development (TDD) запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить Test-Driven Development (TDD) с