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★ 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
- Red-Green-Refactor cycle -- Write failing test (Red) → Make it pass (Green) → Improve code (Refactor).
- Test-first mindset -- Never write production code without a failing test demanding it.
- Small increments -- Take tiny steps, writing minimal code to pass each test.
- Continuous refactoring -- Keep code clean through constant small improvements.
- 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
Установить 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), без исполняемых скриптов.
Похожие скиллы
doc-coauthoring
Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
от Anthropicacademy-guide
Stop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
от Anthropicinternal-comms
A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
от Anthropicskill-development
This skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…
от Anthropic