Tooluck logoTooluck
SKILL.md

red-green-refactor

Agent skill fromrohitg00/skillkit

Guides the red-green-refactor TDD workflow: write a failing test first, implement the minimum code to make it pass, then refactor while keeping tests green. Use when a user asks to practice TDD, write tests first, follow red-green-refactor, do test-driven development, write failing tests before code, or phrases like 'make the test pass', 'test coverage', or 'unit tests before implementation'.

How to install red-green-refactor

install red-green-refactor
# install the skillkit pack with the skills CLI
npx skills add rohitg00/skillkit

# or add only this skill to Claude Code: copy the folder

packages/core/src/methodology/packs/testing/red-green-refactor/

# into

~/.claude/skills/red-green-refactor/ (all projects)

.claude/skills/red-green-refactor/ (one project)

packages/core/src/methodology/packs/testing/red-green-refactor/SKILL.md

Apache-2.0Full file
1# Red-Green-Refactor Methodology
2
3You are following the RED-GREEN-REFACTOR cycle for test-driven development. Every new feature, bug fix, or behavior change starts with a failing test.
4
5## The Cycle
6
7### 1. RED Phase — Write a Failing Test
8
91. **Understand the requirement** — what specific behavior must exist?
102. **Write one test** asserting that behavior
113. **Run the test** — it MUST fail (red)
124. **Verify the failure reason** — not a syntax error, but a missing implementation
13
14The test should be focused on ONE behavior, named descriptively, and use clear assertions.
15
16**Executable example (Jest):**
17```js
18// calculateTotal.test.js
19const { calculateTotal } = require('./calculateTotal');
20
21describe('calculateTotal', () => {
22 it('should apply 10% discount when total exceeds 100', () => {
23 const items = [{ price: 60 }, { price: 60 }]; // total = 120
24 expect(calculateTotal(items)).toBe(108); // 120 * 0.90
25 });
26});
27```
28Running this now produces: `Cannot find module './calculateTotal'` — correct RED state.
29
30---
31
32### 2. GREEN Phase — Make the Test Pass
33
34Write the **minimum code** needed to pass the test. Don't add anything extra.
35
36```js
37// calculateTotal.js
38function calculateTotal(items) {
39 const total = items.reduce((sum, item) => sum + item.price, 0);
40 return total > 100 ? total * 0.9 : total;
41}
42module.exports = { calculateTotal };
43```
44Run the test — it passes. GREEN achieved. Stop here; resist adding more logic.
45
46---
47
48### 3. REFACTOR Phase — Improve the Code
49…

Excerpt shown under the repository's Apache-2.0 license.

More skills in skillkit

Keep exploring

Similar skill repositories

thedotmack /

claude-mem
116k

Persistent Context Across Sessions for Every Agent – Captures everything your agent does during sessions, compresses it with AI, and injects relevant context back into future sessions. Works with Claude Code, OpenClaw, Codex, Gemini, Hermes, Copilot, OpenCode + More

CCCXGHGM+135 skills

Newsletter

Join the Community

Subscribe to our newsletter for the latest news and updates