From example-skills
Enforces test-driven development workflow requiring 80% coverage across unit, integration, and E2E tests via red-green-refactor cycles for new features, bugs, and refactors.
How this skill is triggered — by the user, by Claude, or both
Slash command
/example-skills:tdd-workflowThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Enforces test-driven development principles with comprehensive test coverage across all layers.
Enforces test-driven development principles with comprehensive test coverage across all layers.
Always write tests first, then implement code to make tests pass. No exceptions.
┌────────┐
│ E2E │ (10-20%)
├────────┤
│ INTEG │ (20-30%)
├────────┤
│ UNIT │ (50-70%)
└────────┘
Start with the user story:
As a [role], I want to [action], so that [benefit]
Example:
As a user, I want to search for products by category,
so that I can find relevant items quickly.
Write the test:
describe('ProductSearch', () => {
it('returns products filtered by category', async () => {
const products = await searchProducts({ category: 'electronics' });
expect(products).toHaveLength(5);
expect(products.every(p => p.category === 'electronics')).toBe(true);
});
});
npm test
# ✗ ProductSearch > returns products filtered by category
# TypeError: searchProducts is not a function
This is good! Red phase confirms test is working.
Write just enough code to pass:
export async function searchProducts(filters: SearchFilters) {
const { category } = filters;
return db.products.findMany({
where: { category }
});
}
npm test
# ✓ ProductSearch > returns products filtered by category (42ms)
Now refactor while keeping tests green:
export async function searchProducts(filters: SearchFilters) {
const query = buildSearchQuery(filters);
const results = await executeSearch(query);
return transformResults(results);
}
Run tests again to ensure they still pass.
Purpose: Test individual functions in isolation
describe('calculateDiscount', () => {
it('applies 10% discount for basic tier', () => {
const price = calculateDiscount(100, 'basic');
expect(price).toBe(90);
});
it('applies 20% discount for premium tier', () => {
const price = calculateDiscount(100, 'premium');
expect(price).toBe(80);
});
it('throws error for invalid tier', () => {
expect(() => calculateDiscount(100, 'invalid')).toThrow();
});
});
Purpose: Test multiple components working together
describe('User Registration API', () => {
it('creates user and sends welcome email', async () => {
const response = await request(app)
.post('/api/register')
.send({ email: '[email protected]', password: 'secret' }); // allow-secret
expect(response.status).toBe(201);
expect(response.body.user.email).toBe('[email protected]');
// Verify email was sent
const sentEmails = await testEmailService.getSentEmails();
expect(sentEmails).toHaveLength(1);
expect(sentEmails[0].to).toBe('[email protected]');
});
});
Purpose: Test complete user flows through the UI
test('user can complete checkout process', async ({ page }) => {
await page.goto('/products');
await page.click('[data-testid="add-to-cart"]');
await page.click('[data-testid="cart"]');
await page.click('[data-testid="checkout"]');
await page.fill('[name="cardNumber"]', '4242424242424242');
await page.click('[data-testid="complete-order"]');
await expect(page.locator('.success-message')).toBeVisible();
await expect(page).toHaveURL(/\/order-confirmation/);
});
After implementation, check coverage:
npm test -- --coverage
# Output:
# File | % Stmts | % Branch | % Funcs | % Lines
# --------------|---------|----------|---------|--------
# All files | 84.2 | 78.5 | 91.3 | 85.1
Requirements:
Always test:
// Mock external service
vi.mock('./emailService', () => ({
sendEmail: vi.fn().mockResolvedValue({ success: true })
}));
// Mock database
vi.mock('./db', () => ({
users: {
findUnique: vi.fn().mockResolvedValue({ id: 1, name: 'Test' })
}
}));
// Mock Date.now()
vi.spyOn(Date, 'now').mockReturnValue(1234567890000);
src/
features/
products/
product.service.ts
product.service.test.ts # Unit tests
product.integration.test.ts # Integration tests
product.e2e.test.ts # E2E tests
# Run single test file
npm test -- product.service.test.ts
# Run single test
npm test -- -t "calculates discount correctly"
# Run in watch mode
npm test -- --watch
# Run with coverage
npm test -- --coverage --no-cache
Complements:
Never skip steps. Never commit untested code.
Provides a checklist for code reviews covering functionality, security, performance, maintainability, tests, and quality. Use for pull requests, audits, team standards, and developer training.
npx claudepluginhub a-organvm/a-i--skills --plugin document-skills