cp-toolkit 2.2.3 → 2.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/commands/add.js +23 -16
- package/src/commands/doctor.js +15 -10
- package/src/commands/init.js +55 -16
- package/templates/AGENTS.md +47 -0
- package/templates/ARCHITECTURE.md +42 -0
- package/templates/agents/backend-specialist.md +1 -0
- package/templates/agents/code-archaeologist.md +116 -106
- package/templates/agents/database-architect.md +1 -0
- package/templates/agents/debugger.md +1 -0
- package/templates/agents/devops-engineer.md +1 -0
- package/templates/agents/documentation-writer.md +1 -0
- package/templates/agents/explorer-agent.md +83 -73
- package/templates/agents/frontend-specialist.md +1 -0
- package/templates/agents/game-developer.md +1 -0
- package/templates/agents/mobile-developer.md +1 -0
- package/templates/agents/orchestrator.md +426 -416
- package/templates/agents/penetration-tester.md +1 -0
- package/templates/agents/performance-optimizer.md +1 -0
- package/templates/agents/product-manager.md +122 -112
- package/templates/agents/product-owner.md +105 -95
- package/templates/agents/project-planner.md +416 -406
- package/templates/agents/qa-automation-engineer.md +113 -103
- package/templates/agents/security-auditor.md +1 -0
- package/templates/agents/seo-specialist.md +1 -0
- package/templates/agents/test-engineer.md +1 -0
- package/templates/skills/core/behavioral-modes/SKILL.md +244 -242
- package/templates/skills/core/brainstorming/SKILL.md +166 -163
- package/templates/skills/core/mcp-builder/SKILL.md +178 -176
- package/templates/skills/core/parallel-agents/SKILL.md +187 -175
- package/templates/skills/core/plan-writing/SKILL.md +154 -152
- package/templates/skills/optional/api-patterns/SKILL.md +83 -81
- package/templates/skills/optional/app-builder/SKILL.md +78 -75
- package/templates/skills/optional/app-builder/templates/SKILL.md +41 -39
- package/templates/skills/optional/architecture/SKILL.md +58 -55
- package/templates/skills/optional/bash-linux/SKILL.md +201 -199
- package/templates/skills/optional/code-review-checklist/SKILL.md +110 -109
- package/templates/skills/optional/database-design/SKILL.md +54 -52
- package/templates/skills/optional/deployment-procedures/SKILL.md +243 -241
- package/templates/skills/optional/documentation-templates/SKILL.md +196 -194
- package/templates/skills/optional/frontend-design/SKILL.md +421 -418
- package/templates/skills/optional/game-development/2d-games/SKILL.md +120 -119
- package/templates/skills/optional/game-development/3d-games/SKILL.md +136 -135
- package/templates/skills/optional/game-development/SKILL.md +169 -167
- package/templates/skills/optional/game-development/game-art/SKILL.md +187 -185
- package/templates/skills/optional/game-development/game-audio/SKILL.md +192 -190
- package/templates/skills/optional/game-development/game-design/SKILL.md +131 -129
- package/templates/skills/optional/game-development/mobile-games/SKILL.md +110 -108
- package/templates/skills/optional/game-development/multiplayer/SKILL.md +133 -132
- package/templates/skills/optional/game-development/pc-games/SKILL.md +146 -144
- package/templates/skills/optional/game-development/vr-ar/SKILL.md +124 -123
- package/templates/skills/optional/game-development/web-games/SKILL.md +152 -150
- package/templates/skills/optional/geo-fundamentals/SKILL.md +158 -156
- package/templates/skills/optional/i18n-localization/SKILL.md +156 -154
- package/templates/skills/optional/lint-and-validate/SKILL.md +48 -45
- package/templates/skills/optional/mobile-design/SKILL.md +397 -394
- package/templates/skills/optional/nextjs-react-expert/SKILL.md +271 -267
- package/templates/skills/optional/nodejs-best-practices/SKILL.md +335 -333
- package/templates/skills/optional/performance-profiling/SKILL.md +145 -143
- package/templates/skills/optional/powershell-windows/SKILL.md +169 -167
- package/templates/skills/optional/python-patterns/SKILL.md +443 -441
- package/templates/skills/optional/red-team-tactics/SKILL.md +201 -199
- package/templates/skills/optional/seo-fundamentals/SKILL.md +130 -129
- package/templates/skills/optional/server-management/SKILL.md +163 -161
- package/templates/skills/optional/systematic-debugging/SKILL.md +111 -109
- package/templates/skills/optional/tailwind-patterns/SKILL.md +271 -269
- package/templates/skills/optional/tdd-workflow/SKILL.md +150 -149
- package/templates/skills/optional/testing-patterns/SKILL.md +179 -178
- package/templates/skills/optional/vulnerability-scanner/SKILL.md +278 -276
- package/templates/skills/optional/web-design-guidelines/SKILL.md +60 -57
- package/templates/skills/optional/webapp-testing/SKILL.md +188 -187
|
@@ -1,149 +1,150 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: tdd-workflow
|
|
3
|
-
description: Test-Driven Development workflow principles. RED-GREEN-REFACTOR cycle.
|
|
4
|
-
allowed-tools: Read, Write, Edit, Glob, Grep, Bash
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
|
43
|
-
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
- Test
|
|
49
|
-
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
| **
|
|
61
|
-
| **
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
- Don't
|
|
67
|
-
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
|
79
|
-
|
|
|
80
|
-
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
-
|
|
86
|
-
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
| **
|
|
98
|
-
| **
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
|
108
|
-
|
|
|
109
|
-
|
|
|
110
|
-
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
|
120
|
-
|
|
|
121
|
-
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
|
131
|
-
|
|
|
132
|
-
|
|
|
133
|
-
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
| Agent
|
|
145
|
-
| Agent
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
1
|
+
---
|
|
2
|
+
name: tdd-workflow
|
|
3
|
+
description: Test-Driven Development workflow principles. RED-GREEN-REFACTOR cycle.
|
|
4
|
+
allowed-tools: Read, Write, Edit, Glob, Grep, Bash
|
|
5
|
+
version: '1.0'
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# TDD Workflow
|
|
9
|
+
|
|
10
|
+
> Write tests first, code second.
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## 1. The TDD Cycle
|
|
15
|
+
|
|
16
|
+
```
|
|
17
|
+
🔴 RED → Write failing test
|
|
18
|
+
↓
|
|
19
|
+
🟢 GREEN → Write minimal code to pass
|
|
20
|
+
↓
|
|
21
|
+
🔵 REFACTOR → Improve code quality
|
|
22
|
+
↓
|
|
23
|
+
Repeat...
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## 2. The Three Laws of TDD
|
|
29
|
+
|
|
30
|
+
1. Write production code only to make a failing test pass
|
|
31
|
+
2. Write only enough test to demonstrate failure
|
|
32
|
+
3. Write only enough code to make the test pass
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## 3. RED Phase Principles
|
|
37
|
+
|
|
38
|
+
### What to Write
|
|
39
|
+
|
|
40
|
+
| Focus | Example |
|
|
41
|
+
|-------|---------|
|
|
42
|
+
| Behavior | "should add two numbers" |
|
|
43
|
+
| Edge cases | "should handle empty input" |
|
|
44
|
+
| Error states | "should throw for invalid data" |
|
|
45
|
+
|
|
46
|
+
### RED Phase Rules
|
|
47
|
+
|
|
48
|
+
- Test must fail first
|
|
49
|
+
- Test name describes expected behavior
|
|
50
|
+
- One assertion per test (ideally)
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## 4. GREEN Phase Principles
|
|
55
|
+
|
|
56
|
+
### Minimum Code
|
|
57
|
+
|
|
58
|
+
| Principle | Meaning |
|
|
59
|
+
|-----------|---------|
|
|
60
|
+
| **YAGNI** | You Aren't Gonna Need It |
|
|
61
|
+
| **Simplest thing** | Write the minimum to pass |
|
|
62
|
+
| **No optimization** | Just make it work |
|
|
63
|
+
|
|
64
|
+
### GREEN Phase Rules
|
|
65
|
+
|
|
66
|
+
- Don't write unneeded code
|
|
67
|
+
- Don't optimize yet
|
|
68
|
+
- Pass the test, nothing more
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
## 5. REFACTOR Phase Principles
|
|
73
|
+
|
|
74
|
+
### What to Improve
|
|
75
|
+
|
|
76
|
+
| Area | Action |
|
|
77
|
+
|------|--------|
|
|
78
|
+
| Duplication | Extract common code |
|
|
79
|
+
| Naming | Make intent clear |
|
|
80
|
+
| Structure | Improve organization |
|
|
81
|
+
| Complexity | Simplify logic |
|
|
82
|
+
|
|
83
|
+
### REFACTOR Rules
|
|
84
|
+
|
|
85
|
+
- All tests must stay green
|
|
86
|
+
- Small incremental changes
|
|
87
|
+
- Commit after each refactor
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## 6. AAA Pattern
|
|
92
|
+
|
|
93
|
+
Every test follows:
|
|
94
|
+
|
|
95
|
+
| Step | Purpose |
|
|
96
|
+
|------|---------|
|
|
97
|
+
| **Arrange** | Set up test data |
|
|
98
|
+
| **Act** | Execute code under test |
|
|
99
|
+
| **Assert** | Verify expected outcome |
|
|
100
|
+
|
|
101
|
+
---
|
|
102
|
+
|
|
103
|
+
## 7. When to Use TDD
|
|
104
|
+
|
|
105
|
+
| Scenario | TDD Value |
|
|
106
|
+
|----------|-----------|
|
|
107
|
+
| New feature | High |
|
|
108
|
+
| Bug fix | High (write test first) |
|
|
109
|
+
| Complex logic | High |
|
|
110
|
+
| Exploratory | Low (spike, then TDD) |
|
|
111
|
+
| UI layout | Low |
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
## 8. Test Prioritization
|
|
116
|
+
|
|
117
|
+
| Priority | Test Type |
|
|
118
|
+
|----------|-----------|
|
|
119
|
+
| 1 | Happy path |
|
|
120
|
+
| 2 | Error cases |
|
|
121
|
+
| 3 | Edge cases |
|
|
122
|
+
| 4 | Performance |
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
## 9. Anti-Patterns
|
|
127
|
+
|
|
128
|
+
| ❌ Don't | ✅ Do |
|
|
129
|
+
|----------|-------|
|
|
130
|
+
| Skip the RED phase | Watch test fail first |
|
|
131
|
+
| Write tests after | Write tests before |
|
|
132
|
+
| Over-engineer initial | Keep it simple |
|
|
133
|
+
| Multiple asserts | One behavior per test |
|
|
134
|
+
| Test implementation | Test behavior |
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
## 10. AI-Augmented TDD
|
|
139
|
+
|
|
140
|
+
### Multi-Agent Pattern
|
|
141
|
+
|
|
142
|
+
| Agent | Role |
|
|
143
|
+
|-------|------|
|
|
144
|
+
| Agent A | Write failing tests (RED) |
|
|
145
|
+
| Agent B | Implement to pass (GREEN) |
|
|
146
|
+
| Agent C | Optimize (REFACTOR) |
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
> **Remember:** The test is the specification. If you can't write a test, you don't understand the requirement.
|
|
@@ -1,178 +1,179 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: testing-patterns
|
|
3
|
-
description: Testing patterns and principles. Unit, integration, mocking strategies.
|
|
4
|
-
allowed-tools: Read, Write, Edit, Glob, Grep, Bash
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
| **
|
|
34
|
-
| **
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
| **
|
|
46
|
-
| **
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
|
58
|
-
|
|
|
59
|
-
|
|
|
60
|
-
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
|
68
|
-
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
|
80
|
-
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
| Before
|
|
88
|
-
|
|
|
89
|
-
| After
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
|
101
|
-
|
|
|
102
|
-
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
|
110
|
-
|
|
|
111
|
-
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
|
123
|
-
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
|
131
|
-
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
|
143
|
-
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
-
|
|
149
|
-
-
|
|
150
|
-
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
|
160
|
-
|
|
|
161
|
-
|
|
|
162
|
-
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
|
172
|
-
|
|
|
173
|
-
|
|
|
174
|
-
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
1
|
+
---
|
|
2
|
+
name: testing-patterns
|
|
3
|
+
description: Testing patterns and principles. Unit, integration, mocking strategies.
|
|
4
|
+
allowed-tools: Read, Write, Edit, Glob, Grep, Bash
|
|
5
|
+
version: '1.0'
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Testing Patterns
|
|
9
|
+
|
|
10
|
+
> Principles for reliable test suites.
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## 1. Testing Pyramid
|
|
15
|
+
|
|
16
|
+
```
|
|
17
|
+
/\ E2E (Few)
|
|
18
|
+
/ \ Critical flows
|
|
19
|
+
/----\
|
|
20
|
+
/ \ Integration (Some)
|
|
21
|
+
/--------\ API, DB queries
|
|
22
|
+
/ \
|
|
23
|
+
/------------\ Unit (Many)
|
|
24
|
+
Functions, classes
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## 2. AAA Pattern
|
|
30
|
+
|
|
31
|
+
| Step | Purpose |
|
|
32
|
+
|------|---------|
|
|
33
|
+
| **Arrange** | Set up test data |
|
|
34
|
+
| **Act** | Execute code under test |
|
|
35
|
+
| **Assert** | Verify outcome |
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## 3. Test Type Selection
|
|
40
|
+
|
|
41
|
+
### When to Use Each
|
|
42
|
+
|
|
43
|
+
| Type | Best For | Speed |
|
|
44
|
+
|------|----------|-------|
|
|
45
|
+
| **Unit** | Pure functions, logic | Fast (<50ms) |
|
|
46
|
+
| **Integration** | API, DB, services | Medium |
|
|
47
|
+
| **E2E** | Critical user flows | Slow |
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## 4. Unit Test Principles
|
|
52
|
+
|
|
53
|
+
### Good Unit Tests
|
|
54
|
+
|
|
55
|
+
| Principle | Meaning |
|
|
56
|
+
|-----------|---------|
|
|
57
|
+
| Fast | < 100ms each |
|
|
58
|
+
| Isolated | No external deps |
|
|
59
|
+
| Repeatable | Same result always |
|
|
60
|
+
| Self-checking | No manual verification |
|
|
61
|
+
| Timely | Written with code |
|
|
62
|
+
|
|
63
|
+
### What to Unit Test
|
|
64
|
+
|
|
65
|
+
| Test | Don't Test |
|
|
66
|
+
|------|------------|
|
|
67
|
+
| Business logic | Framework code |
|
|
68
|
+
| Edge cases | Third-party libs |
|
|
69
|
+
| Error handling | Simple getters |
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
## 5. Integration Test Principles
|
|
74
|
+
|
|
75
|
+
### What to Test
|
|
76
|
+
|
|
77
|
+
| Area | Focus |
|
|
78
|
+
|------|-------|
|
|
79
|
+
| API endpoints | Request/response |
|
|
80
|
+
| Database | Queries, transactions |
|
|
81
|
+
| External services | Contracts |
|
|
82
|
+
|
|
83
|
+
### Setup/Teardown
|
|
84
|
+
|
|
85
|
+
| Phase | Action |
|
|
86
|
+
|-------|--------|
|
|
87
|
+
| Before All | Connect resources |
|
|
88
|
+
| Before Each | Reset state |
|
|
89
|
+
| After Each | Clean up |
|
|
90
|
+
| After All | Disconnect |
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
## 6. Mocking Principles
|
|
95
|
+
|
|
96
|
+
### When to Mock
|
|
97
|
+
|
|
98
|
+
| Mock | Don't Mock |
|
|
99
|
+
|------|------------|
|
|
100
|
+
| External APIs | The code under test |
|
|
101
|
+
| Database (unit) | Simple dependencies |
|
|
102
|
+
| Time/random | Pure functions |
|
|
103
|
+
| Network | In-memory stores |
|
|
104
|
+
|
|
105
|
+
### Mock Types
|
|
106
|
+
|
|
107
|
+
| Type | Use |
|
|
108
|
+
|------|-----|
|
|
109
|
+
| Stub | Return fixed values |
|
|
110
|
+
| Spy | Track calls |
|
|
111
|
+
| Mock | Set expectations |
|
|
112
|
+
| Fake | Simplified implementation |
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
## 7. Test Organization
|
|
117
|
+
|
|
118
|
+
### Naming
|
|
119
|
+
|
|
120
|
+
| Pattern | Example |
|
|
121
|
+
|---------|---------|
|
|
122
|
+
| Should behavior | "should return error when..." |
|
|
123
|
+
| When condition | "when user not found..." |
|
|
124
|
+
| Given-when-then | "given X, when Y, then Z" |
|
|
125
|
+
|
|
126
|
+
### Grouping
|
|
127
|
+
|
|
128
|
+
| Level | Use |
|
|
129
|
+
|-------|-----|
|
|
130
|
+
| describe | Group related tests |
|
|
131
|
+
| it/test | Individual case |
|
|
132
|
+
| beforeEach | Common setup |
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
## 8. Test Data
|
|
137
|
+
|
|
138
|
+
### Strategies
|
|
139
|
+
|
|
140
|
+
| Approach | Use |
|
|
141
|
+
|----------|-----|
|
|
142
|
+
| Factories | Generate test data |
|
|
143
|
+
| Fixtures | Predefined datasets |
|
|
144
|
+
| Builders | Fluent object creation |
|
|
145
|
+
|
|
146
|
+
### Principles
|
|
147
|
+
|
|
148
|
+
- Use realistic data
|
|
149
|
+
- Randomize non-essential values (faker)
|
|
150
|
+
- Share common fixtures
|
|
151
|
+
- Keep data minimal
|
|
152
|
+
|
|
153
|
+
---
|
|
154
|
+
|
|
155
|
+
## 9. Best Practices
|
|
156
|
+
|
|
157
|
+
| Practice | Why |
|
|
158
|
+
|----------|-----|
|
|
159
|
+
| One assert per test | Clear failure reason |
|
|
160
|
+
| Independent tests | No order dependency |
|
|
161
|
+
| Fast tests | Run frequently |
|
|
162
|
+
| Descriptive names | Self-documenting |
|
|
163
|
+
| Clean up | Avoid side effects |
|
|
164
|
+
|
|
165
|
+
---
|
|
166
|
+
|
|
167
|
+
## 10. Anti-Patterns
|
|
168
|
+
|
|
169
|
+
| ❌ Don't | ✅ Do |
|
|
170
|
+
|----------|-------|
|
|
171
|
+
| Test implementation | Test behavior |
|
|
172
|
+
| Duplicate test code | Use factories |
|
|
173
|
+
| Complex test setup | Simplify or split |
|
|
174
|
+
| Ignore flaky tests | Fix root cause |
|
|
175
|
+
| Skip cleanup | Reset state |
|
|
176
|
+
|
|
177
|
+
---
|
|
178
|
+
|
|
179
|
+
> **Remember:** Tests are documentation. If someone can't understand what the code does from the tests, rewrite them.
|