From implement-task
TDD methodology for all coding tasks. Use when implementing features, fixing bugs, writing functions, or any task that involves producing or modifying code.
How this skill is triggered — by the user, by Claude, or both
Slash command
/implement-task:tddThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Apply the RED-GREEN-REFACTOR cycle strictly. No production code exists before a failing test.
Apply the RED-GREEN-REFACTOR cycle strictly. No production code exists before a failing test.
Language note: The examples below use Go. Apply the same methodology in whatever language the project uses — the cycle, ordering, and extraction rules are language-agnostic.
Name every test to make the intent self-documenting. A good pattern: <WhatIsTested>_<Expectation>_<Given> or <WhatIsTested>Should<Expectation>When<Given> — adapt to the project's existing convention.
Examples:
TestParseShouldFailWhenGivenNilInputTestCalculateTotalShouldReturnZeroWhenCartIsEmptyTestAuthShouldRejectWhenTokenIsExpiredFailure cases before happy path. Within a cycle:
This ordering guarantees the stub fails each test for the right behavioral reason before any logic is written.
Start every new function/method with a stub so the very first test always fails:
// Go example
func (p *Provider[T]) Save(_ context.Context, _ T) error {
return errors.New("not implemented")
}
Keep the "not implemented" stub at the bottom through each intermediate implementation step. Only remove it when implementing the final happy-path test.
After every GREEN phase, scan the new production code for extraction candidates before moving to the next RED phase. Repeat the same scan at the end of the full TDD cycle.
Extract a block into a helper when it:
Do not extract:
Use active-verb names that describe what is done, not how:
findAndVerifyUser(ctx, email, password) — not getUserWithChecksaveSession(ctx, userID, rawToken) — not sessionCreationretrieveSession(ctx, sessionID, rawRandom) — not getSessionHelperBefore (post-GREEN, no extraction yet):
func (s *AuthService) Login(ctx context.Context, email, password string) (string, error) {
user, err := s.users.FindByEmail(ctx, email)
if err != nil {
return "", err
}
if !verifyPassword(user.PasswordHash, password) {
return "", domain.ErrUnauthorized
}
rawToken := generateToken()
session := domain.Session{UserID: user.ID, TokenHash: hash(rawToken)}
if err := s.sessions.Save(ctx, session); err != nil {
return "", err
}
return rawToken, nil
}
After (post-REFACTOR, helpers extracted):
func (s *AuthService) Login(ctx context.Context, email, password string) (string, error) {
user, err := s.findAndVerifyUser(ctx, email, password)
if err != nil {
return "", err
}
return s.saveSession(ctx, user.ID)
}
Candidates identified: "find user + verify password" (3 lines, one coherent step) → findAndVerifyUser; "create + persist session" (3 lines, one coherent step) → saveSession.
Assert on domain/sentinel errors using the language's idiomatic equality check, never pin to error message strings:
// Go — correct
require.ErrorIs(t, err, domain.ErrIO)
// Go — wrong (brittle, couples test to stdlib internals)
require.ErrorContains(t, err, "no such file or directory")
Wrap infrastructure errors at the boundary before returning so callers receive typed sentinels:
// Go example
return fmt.Errorf("%w: %w", domain.ErrIO, err)
Add error sentinels at the point they are first needed — no pre-emptive catalogue.
ctx, never blank it with _ctx.Err() before any lock or I/O at the start of the functiont.Context() instead of context.Background()t.Context(): ctx, cancel := context.WithCancel(t.Context())Use explicit, readable values (e.g. "42", "[email protected]") rather than zero/empty defaults — intent is clearer and failures are easier to diagnose.
After all RED-GREEN-REFACTOR cycles are complete and tests pass, do a final pass over all production code written in this session:
Before writing any production code, confirm:
<what>_<expectation>_<condition> patternBefore closing a GREEN phase, confirm:
Before closing a REFACTOR phase, confirm:
Guides creation, editing, and verification of skills for AI coding agents using test-driven development with subagent scenarios. Use when authoring or debugging skills.
npx claudepluginhub outfitte/plugins --plugin implement-task