home / skills / dhughes / claude-marketplace / tdd-feature-development

This skill establishes test-driven development requirements before feature work, ensuring explicit test plans and early test-driven implementation.

npx playbooks add skill dhughes/claude-marketplace --skill tdd-feature-development

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
7.9 KB
---
name: tdd-feature-development
description: "CRITICAL: When the user asks to implement/build/add a feature or mentions feature development, invoke this skill FIRST (BEFORE invoking feature-dev or any other feature development workflow). This establishes test-driven development requirements and ensures tests are written early and explicitly planned as separate steps. Do NOT wait until feature-dev is already running - invoke this BEFORE starting any feature development workflow."
version: 0.2.0
---

# TDD Feature Development

This skill augments feature development workflows to ensure test-driven development (TDD) practices are consistently followed. It emphasizes writing tests early, planning them as explicit steps, and maintaining high test coverage.

## Purpose

When implementing features, tests should not be an afterthought. This skill ensures that:

1. Tests are planned as **explicit, separate TODO items** (not buried within implementation steps)
2. Tests are written **alongside code** using a TDD-ish approach (not all at the end)
3. Testing principles are followed throughout the development process
4. Code is designed to be testable from the start

## Critical Workflow Integration

**IMPORTANT:** This skill should be invoked BEFORE any feature development workflow begins (such as feature-dev). The intended flow is:

1. **User requests feature development** (e.g., "implement a login feature")
2. **Invoke tdd-feature-development FIRST** (this skill) to establish TDD requirements
3. **Then invoke feature-dev** (or other feature development workflow) with TDD principles in mind
4. **Follow the guidelines below** throughout the feature development process

Do NOT invoke this skill after feature-dev has already started - it will be too late to integrate TDD principles into the planning phase.

## When to Use This Skill

Apply these guidelines when:
- User requests implementing any new feature or functionality
- User asks to build, add, or create features
- BEFORE invoking feature-dev or similar workflows
- Creating implementation plans or TODO lists for code changes
- Designing architecture for new features

## Core Testing Principles

### Write Tests Early

Tests are the foundation of code quality. Write tests **early** in the development process, not as a final step.

**TDD-ish Approach:** For core business logic, write tests alongside implementation:
1. Design the interface/API
2. Write the test for expected behavior
3. Implement the functionality
4. Refactor if needed
5. Move to next feature

This is not strict TDD (test-first always), but rather a pragmatic approach that ensures tests are written while the implementation context is fresh.

### Test as Separate TODO Items

When creating implementation plans or TODO lists:

**❌ WRONG:**
```
- Implement user authentication service (including tests)
- Add password hashing
- Create login endpoint
```

**✅ CORRECT:**
```
- Design user authentication service interface
- Write tests for user authentication service
- Implement user authentication service
- Write tests for password hashing
- Add password hashing functionality
- Write tests for login endpoint
- Create login endpoint
- Run all tests and verify 80% coverage
```

Each test-writing activity should be a **separate, explicit TODO item** so it's tracked and not forgotten.

### Test Behavior, Not Implementation (CRITICAL)

**Tests should verify WHAT the code does (behavior/features), not HOW it does it (implementation details).**

This is one of the most important testing principles. Tests should:
- Focus on the **public API** and observable behavior
- Verify **features and outcomes**, not internal mechanics
- Be resilient to refactoring (implementation changes shouldn't break tests)

**Good Examples:**
- Test that `authenticateUser()` returns a valid token for correct credentials
- Test that invalid credentials return an appropriate error
- Test that expired tokens are rejected

**Bad Examples:**
- Test that `authenticateUser()` calls specific internal helper methods
- Test that a private `_hashPassword()` function is invoked
- Test the order of internal operations

If the implementation changes but the behavior stays the same, tests should still pass.

### Don't Test Private Functions (CRITICAL)

**Never write tests for private/internal functions or methods.**

Test only the **public API** and observable behavior. Private functions are implementation details that:
- Should be tested indirectly through the public API
- May change frequently during refactoring
- Create brittle, implementation-coupled tests

If a private function feels like it needs its own tests, consider:
1. Is it complex enough to be extracted as its own public module?
2. Is the public API properly testing all the behaviors this private function enables?

**The solution is better design, not testing private functions.**

### Aim for 80% Test Coverage

Target 80% code coverage as a baseline for quality. This ensures most code paths are exercised without requiring 100% coverage on trivial code.

## Integration with Feature Development Workflows

### During Phase 1: Discovery

When understanding requirements, consider:
- What behaviors need to be tested?
- Are there edge cases that need test coverage?
- What's the testability of the proposed solution?

### During Phase 4: Architecture Design

When evaluating approaches, consider:
- Is this design testable?
- Can core logic be isolated for unit testing?
- Are dependencies injected to allow mocking?

Prefer architectures that enable easy testing. Code that's hard to test is often poorly designed.

### During Phase 5: Implementation

**CRITICAL:** When creating the implementation plan and TODO list:

1. **Break down each feature into implementation + test pairs**
2. **Add separate TODO items for writing tests**
3. **Place test items BEFORE or ALONGSIDE their implementation items**

For example, when implementing a new API endpoint:
```
- Design endpoint interface and response schema
- Write tests for successful request case
- Write tests for validation errors
- Write tests for authentication failures
- Implement endpoint handler
- Run tests and verify they pass
```

**NOT:**
```
- Implement endpoint
- Add tests later
```

4. **Include a final TODO for running tests and checking coverage**

### During Phase 6: Quality Review

Verify:
- Are tests written for all new functionality?
- Do tests cover edge cases and error conditions?
- Is test coverage at or above 80%?
- Are tests testing behavior rather than implementation?

## Project-Agnostic Guidelines

This skill does NOT specify:
- How to run tests (pytest, npm test, etc.) - that's project-specific
- Where test files should be located - that's project-specific
- What testing framework to use - that's project-specific

This skill DOES specify:
- Tests must be written early
- Tests must be planned as explicit TODO items
- Tests must be written alongside code, not at the end
- Test coverage should reach 80%
- Tests should focus on behavior, not implementation

## Key Reminders

1. **Tests are not optional** - They're part of the feature implementation
2. **Tests are not afterthoughts** - Plan them from the start
3. **Tests are separate steps** - Don't hide them in implementation TODOs
4. **Tests guide design** - Hard-to-test code is often bad design
5. **Run tests frequently** - Catch issues early

## Practical Workflow

When creating an implementation plan:

1. **Review the architecture/design**
2. **Identify all components that need implementation**
3. **For each component:**
   - Add TODO: "Write tests for [component]"
   - Add TODO: "Implement [component]"
4. **Add TODO: "Run full test suite and verify 80% coverage"**
5. **Begin implementation**, marking TODOs complete as you go

This ensures tests are visible, tracked, and completed alongside implementation rather than being forgotten or delayed until the end.

---

By following these guidelines, feature development naturally incorporates testing as a first-class activity, resulting in higher quality, more maintainable code with fewer bugs.

Overview

This skill enforces test-driven development practices before any feature development begins. It ensures tests are planned explicitly, written early alongside implementation, and that designs remain testable to achieve reliable, maintainable code.

How this skill works

When a user requests a feature, invoke this skill first to establish TDD requirements and a testing-first plan. It produces TODO-style steps that separate test-writing from implementation, enforces behavior-focused tests, and sets a target coverage baseline to guide the subsequent feature-dev workflow.

When to use it

  • When the user asks to implement, add, or build any new feature
  • Before invoking any feature development workflow (e.g., feature-dev)
  • When creating implementation plans, TODO lists, or user stories
  • During discovery, architecture design, and implementation planning
  • When assessing testability of proposed designs

Best practices

  • Make every test-writing activity an explicit TODO item separate from implementation
  • Write tests early — alongside or immediately before implementing each piece of functionality
  • Test observable behavior and public APIs; avoid testing private/internal functions
  • Design code for testability: inject dependencies and isolate core logic for unit tests
  • Aim for at least 80% test coverage as a baseline and include a final coverage check in the plan

Example use cases

  • User requests a new authentication endpoint — produce a plan that lists tests for success, validation, and failure cases before implementation
  • Planning a new microservice — add TODOs for interface design, behavior tests, mockable dependency wiring, then implementation
  • Adding a feature flag — write tests for toggle behavior and rollout scenarios before coding the flag logic
  • Refactoring a module — create tests for the public behavior first, then refactor safely with tests guarding regressions

FAQ

What exactly should I invoke first when a feature is requested?

Invoke this TDD skill before any feature-dev workflow so test planning is embedded in the initial plan rather than appended later.

Should I test private functions if they are complex?

No. Test behavior through the public API. If a private function needs direct tests, consider refactoring it into its own testable public module.