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.
What this skill does
# TDD Workflow Skill
This skill provides guidance for Test-Driven Development methodology.
## The Core Cycle
```
┌─────────────────────────────────────────────────┐
│ │
│ ┌───────┐ ┌───────┐ ┌──────────┐ │
│ │ RED │ ──▶ │ GREEN │ ──▶ │ REFACTOR │ │
│ └───────┘ └───────┘ └──────────┘ │
│ │ │ │
│ └─────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────┘
```
## Phase 1: RED - Write a Failing Test
### Purpose
Define the expected behavior BEFORE writing implementation.
### Actions
1. Create or open test file
2. Write a test that describes ONE behavior
3. Run the test
4. Verify it FAILS (important!)
### Example (TypeScript/Jest)
```typescript
describe('UserService', () => {
describe('createUser', () => {
it('should create a user with valid email', async () => {
const user = await userService.createUser({
email: '[email protected]',
name: 'Test User'
});
expect(user.id).toBeDefined();
expect(user.email).toBe('[email protected]');
});
it('should throw error for invalid email', async () => {
await expect(
userService.createUser({ email: 'invalid', name: 'Test' })
).rejects.toThrow('Invalid email format');
});
});
});
```
### Common Mistakes
- Writing tests that pass immediately (means the test is wrong)
- Testing implementation details instead of behavior
- Writing too many tests before any implementation
## Phase 2: GREEN - Make It Pass
### Purpose
Write the MINIMUM code to make the test pass.
### Actions
1. Implement just enough to pass the failing test
2. No extra features
3. No optimization
4. Run tests to verify PASS
### Example
```typescript
// 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
};
}
}
```
### Common Mistakes
- Over-engineering on first pass
- Adding features not covered by tests
- "While I'm here" additions
## Phase 3: REFACTOR - Improve Quality
### Purpose
Clean up the code while keeping tests green.
### Actions
1. Look for improvements:
- Duplication
- Poor naming
- Complex logic
- Long functions
2. Make ONE change
3. Run tests
4. If green, continue. If red, undo.
### Example
```typescript
// 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()
};
}
}
```
### Refactoring Checklist
- [ ] Extract long methods
- [ ] Rename unclear variables/functions
- [ ] Remove duplication (DRY)
- [ ] Simplify conditionals
- [ ] Add type safety
## Test Patterns
### Arrange-Act-Assert (AAA)
```typescript
it('should calculate discount correctly', () => {
// Arrange
const cart = new Cart();
cart.addItem({ price: 100 });
// Act
const discount = cart.calculateDiscount();
// Assert
expect(discount).toBe(10);
});
```
### Given-When-Then (BDD)
```typescript
describe('given a cart with items over $100', () => {
describe('when calculating discount', () => {
it('then should apply 10% discount', () => {
// ...
});
});
});
```
## Coverage Commands
### JavaScript/TypeScript
```bash
# Jest
npx jest --coverage
# Vitest
npx vitest run --coverage
```
### Python
```bash
pytest --cov=src --cov-report=html
```
### Go
```bash
go test -cover ./...
go test -coverprofile=coverage.out ./...
```
## Anti-Patterns
### 1. Test After
Writing code first, tests second defeats the purpose.
### 2. Testing Implementation
```typescript
// BAD: Testing HOW it works
expect(service.internalMethod).toHaveBeenCalled();
// GOOD: Testing WHAT it does
expect(result).toEqual(expectedOutput);
```
### 3. Brittle Tests
```typescript
// BAD: Breaks if order changes
expect(users[0].name).toBe('Alice');
// GOOD: Resilient assertion
expect(users).toContainEqual(expect.objectContaining({ name: 'Alice' }));
```
### 4. No Refactoring
Skipping refactor phase leads to technical debt.
## Quick Reference
| 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 |
## Integration
This skill works with:
- **conductor-context**: For project-specific coverage targets
- **code-styleguides**: For language-specific test patterns
Related in Writing & Docs
jax-development
IncludedUse this skill when the user is writing, debugging, profiling, refactoring, reviewing, benchmarking, parallelising, exporting, or explaining JAX code, or when they mention JAX, jax.numpy, jit, grad, value_and_grad, vmap, scan, lax, random keys, pytrees, jax.Array, sharding, Mesh, PartitionSpec, NamedSharding, pmap, shard_map, Pallas, XLA, StableHLO, checkify, profiler, or the JAX repo. It helps turn NumPy or PyTorch-style code into pure functional JAX, fix tracer/control-flow/shape/PRNG bugs, remove recompiles and host-device syncs, choose transforms and sharding strategies, inspect jaxpr/lowering/IR, and benchmark compiled code correctly.
nature-article-writer
IncludedDrafts, rewrites, diagnostically critiques, and style-calibrates primary research manuscripts for Nature and Nature Portfolio journals. Use when the user wants a Nature-style title, summary paragraph or abstract, introduction, results, discussion, methods, figure legends, presubmission enquiry, cover letter, reviewer response, or when a scientific draft sounds generic, jargon-heavy, structurally weak, or AI-ish and needs precise, broad-reader-friendly prose without inventing data, analyses, or references. Best for primary research articles and letters rather than reviews or press releases unless explicitly adapting one.
deckrd
IncludedDocument-driven framework that derives requirements, specifications, implementation plans, and executable tasks from goals through structured AI dialogue. Use when user says "write requirements", "create spec", "plan implementation", "derive tasks", "structure this feature", "break down into tasks", or "document this module". Also use for reverse engineering existing code into docs (/deckrd rev). Do NOT use for direct code writing — use /deckrd-coder after tasks are generated. Do NOT use when the user only wants to run or fix existing code without planning.
clinical-decision-support
IncludedGenerate professional clinical decision support (CDS) documents for pharmaceutical and clinical research settings, including patient cohort analyses (biomarker-stratified with outcomes) and treatment recommendation reports (evidence-based guidelines with decision algorithms). Supports GRADE evidence grading, statistical analysis (hazard ratios, survival curves, waterfall plots), biomarker integration, and regulatory compliance. Outputs publication-ready LaTeX/PDF format optimized for drug development, clinical research, and evidence synthesis.
handling-sf-data
IncludedSalesforce data operations with 130-point scoring. Use this skill to create, update, delete, bulk import/export, generate test data, and clean up org records using sf CLI and anonymous Apex. TRIGGER when: user creates test data, performs bulk import/export, uses sf data CLI commands, needs data factory patterns for Apex tests, or needs to seed/clean records in a Salesforce org. DO NOT TRIGGER when: SOQL query writing only (use querying-soql), Apex test execution (use running-apex-tests), or metadata deployment (use deploying-metadata).
accelint-ac-to-playwright
IncludedConvert and validate acceptance criteria for Playwright test automation. Use when user asks to (1) review/evaluate/check if AC are ready for automation, (2) assess if AC can be converted as-is, (3) validate AC quality for Playwright, (4) turn AC into tests, (5) generate tests from acceptance criteria, (6) convert .md bullets or .feature Gherkin files to Playwright specs, (7) create test automation from requirements. Handles both bullet-style markdown and Gherkin syntax with JSON test plan generation and validation.