mit einem Klick
tdd-workflow
// Test-Driven Development guidance. Use when writing code, implementing features, or fixing bugs in projects that follow TDD methodology. Provides the Red-Green-Refactor cycle structure.
// Test-Driven Development guidance. Use when writing code, implementing features, or fixing bugs in projects that follow TDD methodology. Provides the Red-Green-Refactor cycle structure.
Language-specific code style guidelines. Use when writing TypeScript, Python, Go, JavaScript, or HTML/CSS code to ensure consistent, idiomatic, and maintainable code following best practices.
Auto-load Conductor project context when conductor/ directory exists. Use for any development task in a Conductor-managed project to ensure alignment with product goals, tech stack, and workflow methodology.
Test-Driven Development guidance. Use when writing code, implementing features, or fixing bugs in projects that follow TDD methodology. Provides the Red-Green-Refactor cycle structure.
Auto-load Conductor project context when conductor/ directory exists. Use for any development task in a Conductor-managed project to ensure alignment with product goals, tech stack, and workflow methodology.
| name | tdd-workflow |
| description | Test-Driven Development guidance. Use when writing code, implementing features, or fixing bugs in projects that follow TDD methodology. Provides the Red-Green-Refactor cycle structure. |
This skill provides guidance for Test-Driven Development methodology.
┌─────────────────────────────────────────────────┐
│ │
│ ┌───────┐ ┌───────┐ ┌──────────┐ │
│ │ RED │ ──▶ │ GREEN │ ──▶ │ REFACTOR │ │
│ └───────┘ └───────┘ └──────────┘ │
│ │ │ │
│ └─────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────┘
Define the expected behavior BEFORE writing implementation.
describe('UserService', () => {
describe('createUser', () => {
it('should create a user with valid email', async () => {
const user = await userService.createUser({
email: 'test@example.com',
name: 'Test User'
});
expect(user.id).toBeDefined();
expect(user.email).toBe('test@example.com');
});
it('should throw error for invalid email', async () => {
await expect(
userService.createUser({ email: 'invalid', name: 'Test' })
).rejects.toThrow('Invalid email format');
});
});
});
Write the MINIMUM code to make the test pass.
// MINIMUM implementation to pass the tests above
class UserService {
async createUser(data: { email: string; name: string }) {
if (!data.email.includes('@')) {
throw new Error('Invalid email format');
}
return {
id: crypto.randomUUID(),
email: data.email,
name: data.name
};
}
}
Clean up the code while keeping tests green.
// REFACTORED version
const EMAIL_REGEX = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
class UserService {
async createUser(data: CreateUserInput): Promise<User> {
this.validateEmail(data.email);
return this.buildUser(data);
}
private validateEmail(email: string): void {
if (!EMAIL_REGEX.test(email)) {
throw new InvalidEmailError(email);
}
}
private buildUser(data: CreateUserInput): User {
return {
id: crypto.randomUUID(),
...data,
createdAt: new Date()
};
}
}
it('should calculate discount correctly', () => {
// Arrange
const cart = new Cart();
cart.addItem({ price: 100 });
// Act
const discount = cart.calculateDiscount();
// Assert
expect(discount).toBe(10);
});
describe('given a cart with items over $100', () => {
describe('when calculating discount', () => {
it('then should apply 10% discount', () => {
// ...
});
});
});
# Jest
npx jest --coverage
# Vitest
npx vitest run --coverage
pytest --cov=src --cov-report=html
go test -cover ./...
go test -coverprofile=coverage.out ./...
Writing code first, tests second defeats the purpose.
// BAD: Testing HOW it works
expect(service.internalMethod).toHaveBeenCalled();
// GOOD: Testing WHAT it does
expect(result).toEqual(expectedOutput);
// BAD: Breaks if order changes
expect(users[0].name).toBe('Alice');
// GOOD: Resilient assertion
expect(users).toContainEqual(expect.objectContaining({ name: 'Alice' }));
Skipping refactor phase leads to technical debt.
| Phase | Question to Answer | Action |
|---|---|---|
| RED | What should it do? | Write failing test |
| GREEN | Does it work? | Write minimal code |
| REFACTOR | Is it clean? | Improve structure |
This skill works with: