Agent skill
tdd
Test-Driven Development workflow with RED-GREEN-REFACTOR cycle
Install this agent skill to your Project
npx add-skill https://github.com/48Nauts-Operator/opencode-baseline/tree/main/.opencode/skill/tdd
Metadata
Additional technical details for this skill
- audience
- developers
- workflow
- development
SKILL.md
What I Do
- Guide you through the RED-GREEN-REFACTOR cycle
- Write failing tests first, then implementation
- Ensure tests are meaningful and not just passing
- Prevent common TDD anti-patterns
When to Use Me
Use this skill when:
- Implementing new features
- Fixing bugs (write a failing test that reproduces the bug first)
- Refactoring existing code (ensure tests exist first)
The TDD Cycle
1. RED - Write a Failing Test
1. Write a test for the NEXT small piece of functionality
2. Run the test - it MUST fail
3. If it passes, either:
- The functionality already exists, or
- The test is wrong
The test should:
- Test ONE thing
- Have a descriptive name explaining the behavior
- Follow Arrange-Act-Assert pattern
2. GREEN - Make It Pass
1. Write the MINIMUM code to make the test pass
2. Don't worry about elegance yet
3. Hardcoding is acceptable temporarily
4. Run the test - it MUST pass
Rules:
- Only write code that makes a failing test pass
- Don't add functionality without a test
- Keep changes small
3. REFACTOR - Clean Up
1. Improve code quality while keeping tests green
2. Remove duplication
3. Improve naming
4. Extract methods/functions
5. Run tests after EVERY change
Anti-Patterns to Avoid
| Anti-Pattern | Problem | Solution |
|---|---|---|
| Writing tests after code | Tests validate implementation, not behavior | Always write test first |
| Testing implementation details | Brittle tests that break on refactor | Test public behavior only |
| Large test steps | Hard to identify what broke | Smaller increments |
| Skipping refactor phase | Technical debt accumulates | Always refactor after green |
| Testing trivial code | Wasted effort | Focus on logic and edge cases |
Test Structure
describe('ComponentName', () => {
describe('methodName', () => {
it('should [expected behavior] when [condition]', () => {
// Arrange - set up test data
// Act - call the method
// Assert - verify the result
});
});
});
Commit Rhythm
1. RED: Don't commit (test is failing)
2. GREEN: Commit with "test: add test for X"
3. REFACTOR: Commit with "refactor: improve X"
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
file-organizer
Organize files and folders intelligently with duplicate detection
nx-workspace-patterns
Configure and optimize Nx monorepo workspaces. Use when setting up Nx, configuring project boundaries, optimizing build caching, or implementing affected commands.
auth-implementation-patterns
Master authentication and authorization patterns including JWT, OAuth2, session management, and RBAC to build secure, scalable access control systems. Use when implementing auth systems, securing APIs, or debugging security issues.
sql-optimization-patterns
Master SQL query optimization, indexing strategies, and EXPLAIN analysis to dramatically improve database performance and eliminate slow queries. Use when debugging slow queries, designing database schemas, or optimizing application performance.
monorepo-management
Master monorepo management with Turborepo, Nx, and pnpm workspaces to build efficient, scalable multi-package repositories with optimized builds and dependency management. Use when setting up monorepos, optimizing builds, or managing shared dependencies.
git-advanced-workflows
Master advanced Git workflows including rebasing, cherry-picking, bisect, worktrees, and reflog to maintain clean history and recover from any situation. Use when managing complex Git histories, collaborating on feature branches, or troubleshooting repository issues.
Didn't find tool you were looking for?