ai-flow-dev 1.0.1
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/LICENSE +21 -0
- package/README.md +408 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +791 -0
- package/dist/cli.js.map +1 -0
- package/dist/fs-utils.d.ts +2 -0
- package/dist/fs-utils.d.ts.map +1 -0
- package/dist/fs-utils.js +46 -0
- package/dist/fs-utils.js.map +1 -0
- package/package.json +71 -0
- package/prompts/backend/flow-dev-feature.md +1318 -0
- package/prompts/backend/flow-dev-fix.md +903 -0
- package/prompts/backend/flow-dev-refactor.md +715 -0
- package/prompts/backend/flow-dev-review.md +401 -0
- package/prompts/backend/flow-dev-work.md +1129 -0
- package/prompts/backend/flow-docs-gen-phase-0.md +1840 -0
- package/prompts/backend/flow-docs-gen-phase-1.md +435 -0
- package/prompts/backend/flow-docs-gen-phase-2.md +460 -0
- package/prompts/backend/flow-docs-gen-phase-3.md +684 -0
- package/prompts/backend/flow-docs-gen-phase-4.md +516 -0
- package/prompts/backend/flow-docs-gen-phase-5.md +637 -0
- package/prompts/backend/flow-docs-gen-phase-6.md +465 -0
- package/prompts/backend/flow-docs-gen-phase-7.md +1207 -0
- package/prompts/backend/flow-docs-gen.md +820 -0
- package/prompts/backend/flow-docs-sync.md +526 -0
- package/prompts/backend/flow-project-init.md +248 -0
- package/prompts/backend/flow-project-roadmap.md +1159 -0
- package/prompts/frontend/flow-docs-gen-phase-0.md +494 -0
- package/prompts/frontend/flow-docs-gen-phase-1.md +449 -0
- package/prompts/frontend/flow-docs-gen-phase-2.md +983 -0
- package/prompts/frontend/flow-docs-gen-phase-3.md +685 -0
- package/prompts/frontend/flow-docs-gen-phase-4.md +480 -0
- package/prompts/frontend/flow-docs-gen-phase-5.md +483 -0
- package/prompts/frontend/flow-docs-gen-phase-6.md +570 -0
- package/prompts/frontend/flow-docs-gen-phase-7.md +582 -0
- package/prompts/frontend/flow-docs-gen.md +413 -0
- package/prompts/frontend/flow-docs-sync.md +561 -0
- package/prompts/mobile/flow-docs-gen-phase-0.md +387 -0
- package/prompts/mobile/flow-docs-gen-phase-1.md +530 -0
- package/prompts/mobile/flow-docs-gen-phase-2.md +584 -0
- package/prompts/mobile/flow-docs-gen-phase-3.md +659 -0
- package/prompts/mobile/flow-docs-gen-phase-4.md +363 -0
- package/prompts/mobile/flow-docs-gen-phase-5.md +369 -0
- package/prompts/mobile/flow-docs-gen-phase-6.md +490 -0
- package/prompts/mobile/flow-docs-gen-phase-7.md +407 -0
- package/prompts/mobile/flow-docs-gen.md +430 -0
- package/prompts/mobile/flow-docs-sync.md +634 -0
- package/templates/backend/.clauderules.template +111 -0
- package/templates/backend/.cursorrules.template +102 -0
- package/templates/backend/.env.example.template +122 -0
- package/templates/backend/README.template.md +200 -0
- package/templates/backend/ai-instructions.template.md +354 -0
- package/templates/backend/copilot-instructions.template.md +160 -0
- package/templates/backend/docs/api.template.md +251 -0
- package/templates/backend/docs/architecture.template.md +612 -0
- package/templates/backend/docs/business-flows.template.md +109 -0
- package/templates/backend/docs/code-standards.template.md +828 -0
- package/templates/backend/docs/contributing.template.md +163 -0
- package/templates/backend/docs/data-model.template.md +416 -0
- package/templates/backend/docs/operations.template.md +591 -0
- package/templates/backend/docs/testing.template.md +762 -0
- package/templates/backend/project-brief.template.md +176 -0
- package/templates/backend/specs/configuration.template.md +133 -0
- package/templates/backend/specs/security.template.md +422 -0
- package/templates/frontend/README.template.md +121 -0
- package/templates/frontend/ai-instructions.template.md +368 -0
- package/templates/frontend/docs/api-integration.template.md +390 -0
- package/templates/frontend/docs/components.template.md +567 -0
- package/templates/frontend/docs/error-handling.template.md +385 -0
- package/templates/frontend/docs/operations.template.md +123 -0
- package/templates/frontend/docs/performance.template.md +140 -0
- package/templates/frontend/docs/pwa.template.md +135 -0
- package/templates/frontend/docs/state-management.template.md +394 -0
- package/templates/frontend/docs/styling.template.md +779 -0
- package/templates/frontend/docs/testing.template.md +736 -0
- package/templates/frontend/project-brief.template.md +55 -0
- package/templates/frontend/specs/accessibility.template.md +111 -0
- package/templates/frontend/specs/configuration.template.md +520 -0
- package/templates/frontend/specs/security.template.md +197 -0
- package/templates/fullstack/README.template.md +282 -0
- package/templates/fullstack/ai-instructions.template.md +487 -0
- package/templates/fullstack/project-brief.template.md +197 -0
- package/templates/fullstack/specs/configuration.template.md +380 -0
- package/templates/mobile/AGENT.template.md +251 -0
- package/templates/mobile/README.template.md +195 -0
- package/templates/mobile/ai-instructions.template.md +221 -0
- package/templates/mobile/docs/app-store.template.md +163 -0
- package/templates/mobile/docs/architecture.template.md +100 -0
- package/templates/mobile/docs/native-features.template.md +137 -0
- package/templates/mobile/docs/navigation.template.md +81 -0
- package/templates/mobile/docs/offline-strategy.template.md +90 -0
- package/templates/mobile/docs/permissions.template.md +70 -0
- package/templates/mobile/docs/state-management.template.md +116 -0
- package/templates/mobile/docs/testing.template.md +146 -0
- package/templates/mobile/project-brief.template.md +97 -0
- package/templates/mobile/specs/build-configuration.template.md +116 -0
- package/templates/mobile/specs/deployment.template.md +114 -0
- package/templates/shared/AGENT.template.md +252 -0
|
@@ -0,0 +1,762 @@
|
|
|
1
|
+
# Testing Strategy
|
|
2
|
+
|
|
3
|
+
> Testing approach, standards, and quality requirements for {{PROJECT_NAME}}
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 🎯 Testing Philosophy
|
|
8
|
+
|
|
9
|
+
{{TESTING_PHILOSOPHY}}
|
|
10
|
+
|
|
11
|
+
**Quality Gates:**
|
|
12
|
+
- Minimum {{MIN_COVERAGE}}% code coverage
|
|
13
|
+
- All tests must pass before merge
|
|
14
|
+
- No skipped tests in main branch
|
|
15
|
+
- Critical paths require integration tests
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## 🧪 Testing Framework
|
|
20
|
+
|
|
21
|
+
**Primary Framework:** {{TEST_FRAMEWORK}}
|
|
22
|
+
|
|
23
|
+
**Assertion Library:** {{ASSERTION_LIBRARY}}
|
|
24
|
+
|
|
25
|
+
**Mocking Library:** {{MOCKING_LIBRARY}}
|
|
26
|
+
|
|
27
|
+
**Test Runner:** {{TEST_RUNNER}}
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## 📊 Test Types
|
|
32
|
+
|
|
33
|
+
### Unit Tests ({{UNIT_TEST_PERCENTAGE}}% of tests)
|
|
34
|
+
|
|
35
|
+
**Purpose:** Test individual functions/methods in isolation
|
|
36
|
+
|
|
37
|
+
**Characteristics:**
|
|
38
|
+
- Fast execution (milliseconds)
|
|
39
|
+
- No external dependencies
|
|
40
|
+
- Mock all dependencies
|
|
41
|
+
- Test single responsibility
|
|
42
|
+
|
|
43
|
+
**Coverage Target:** {{UNIT_COVERAGE_TARGET}}%+
|
|
44
|
+
|
|
45
|
+
**What to test:**
|
|
46
|
+
- ✅ Services and business logic
|
|
47
|
+
- ✅ Utilities and helpers
|
|
48
|
+
- ✅ Pure functions
|
|
49
|
+
- ✅ Validation logic
|
|
50
|
+
- ✅ Transformations and calculations
|
|
51
|
+
|
|
52
|
+
**What NOT to test:**
|
|
53
|
+
- ❌ Framework code
|
|
54
|
+
- ❌ Third-party libraries
|
|
55
|
+
- ❌ Simple getters/setters
|
|
56
|
+
- ❌ DTOs without logic
|
|
57
|
+
|
|
58
|
+
**Example:**
|
|
59
|
+
```{{LANGUAGE}}
|
|
60
|
+
{{UNIT_TEST_EXAMPLE}}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Integration Tests ({{INTEGRATION_TEST_PERCENTAGE}}% of tests)
|
|
64
|
+
|
|
65
|
+
**Purpose:** Test multiple components working together
|
|
66
|
+
|
|
67
|
+
**Characteristics:**
|
|
68
|
+
- Slower than unit tests (seconds)
|
|
69
|
+
- Real database {{#IF_TEST_DB}}({{TEST_DB_TYPE}}){{/IF_TEST_DB}}
|
|
70
|
+
- Real external service connections (or reliable mocks)
|
|
71
|
+
- Test data flow through layers
|
|
72
|
+
|
|
73
|
+
**Coverage Target:** {{INTEGRATION_COVERAGE_TARGET}}%+
|
|
74
|
+
|
|
75
|
+
**What to test:**
|
|
76
|
+
- ✅ Controller → Service → Repository flow
|
|
77
|
+
- ✅ Database queries and transactions
|
|
78
|
+
- ✅ Authentication/Authorization flows
|
|
79
|
+
- ✅ Critical business workflows
|
|
80
|
+
- ✅ External API integrations
|
|
81
|
+
|
|
82
|
+
**Example:**
|
|
83
|
+
```{{LANGUAGE}}
|
|
84
|
+
{{INTEGRATION_TEST_EXAMPLE}}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### End-to-End Tests ({{E2E_TEST_PERCENTAGE}}% of tests)
|
|
88
|
+
|
|
89
|
+
**Purpose:** Test complete user flows from API request to response
|
|
90
|
+
|
|
91
|
+
**Characteristics:**
|
|
92
|
+
- Slowest (seconds to minutes)
|
|
93
|
+
- Full application stack
|
|
94
|
+
- Real database
|
|
95
|
+
- Real HTTP requests
|
|
96
|
+
|
|
97
|
+
**Coverage Target:** {{E2E_COVERAGE_TARGET}}%+
|
|
98
|
+
|
|
99
|
+
**What to test:**
|
|
100
|
+
- ✅ Critical user journeys
|
|
101
|
+
- ✅ Authentication flows (login, signup, password reset)
|
|
102
|
+
- ✅ Core business processes
|
|
103
|
+
- ✅ Payment flows
|
|
104
|
+
- ✅ Data export/import
|
|
105
|
+
|
|
106
|
+
**Tool:** {{E2E_TOOL}}
|
|
107
|
+
|
|
108
|
+
**Example:**
|
|
109
|
+
```{{LANGUAGE}}
|
|
110
|
+
{{E2E_TEST_EXAMPLE}}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
{{#IF CONTRACT_TESTS}}
|
|
114
|
+
### Contract Tests
|
|
115
|
+
|
|
116
|
+
**Purpose:** Verify API contracts between services/consumers
|
|
117
|
+
|
|
118
|
+
**Tool:** {{CONTRACT_TEST_TOOL}}
|
|
119
|
+
|
|
120
|
+
**When to use:**
|
|
121
|
+
- Microservices architecture
|
|
122
|
+
- External API consumers
|
|
123
|
+
- Frontend/Backend contracts
|
|
124
|
+
|
|
125
|
+
**Strategy:**
|
|
126
|
+
- Consumer-driven contracts (CDC)
|
|
127
|
+
- Provider contracts verification
|
|
128
|
+
- Contract versioning
|
|
129
|
+
|
|
130
|
+
**Example:**
|
|
131
|
+
```{{LANGUAGE}}
|
|
132
|
+
{{CONTRACT_TEST_EXAMPLE}}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
**Contract Management:**
|
|
136
|
+
- Contract storage: {{CONTRACT_STORAGE}}
|
|
137
|
+
- Versioning: {{CONTRACT_VERSIONING}}
|
|
138
|
+
- Breaking changes: {{CONTRACT_BREAKING_CHANGES}}
|
|
139
|
+
|
|
140
|
+
{{/IF}}
|
|
141
|
+
|
|
142
|
+
{{#IF PERFORMANCE_TESTS}}
|
|
143
|
+
### Performance Tests
|
|
144
|
+
|
|
145
|
+
**Purpose:** Verify system performance under load
|
|
146
|
+
|
|
147
|
+
**Tool:** {{PERFORMANCE_TEST_TOOL}}
|
|
148
|
+
|
|
149
|
+
**Test Types:**
|
|
150
|
+
- **Load Testing**: Normal expected load
|
|
151
|
+
- **Stress Testing**: Beyond normal capacity
|
|
152
|
+
- **Spike Testing**: Sudden load increases
|
|
153
|
+
- **Endurance Testing**: Sustained load over time
|
|
154
|
+
|
|
155
|
+
**Metrics:**
|
|
156
|
+
- Response time (p50, p95, p99)
|
|
157
|
+
- Throughput (requests/second)
|
|
158
|
+
- Error rate
|
|
159
|
+
- Resource usage (CPU, memory, disk, network)
|
|
160
|
+
|
|
161
|
+
**Thresholds:**
|
|
162
|
+
{{#EACH PERFORMANCE_THRESHOLD}}
|
|
163
|
+
- {{METRIC_NAME}}: {{THRESHOLD_VALUE}}
|
|
164
|
+
{{/EACH}}
|
|
165
|
+
|
|
166
|
+
**Test Scenarios:**
|
|
167
|
+
{{#EACH PERFORMANCE_SCENARIO}}
|
|
168
|
+
#### {{SCENARIO_NAME}}
|
|
169
|
+
|
|
170
|
+
- Load: {{SCENARIO_LOAD}}
|
|
171
|
+
- Duration: {{SCENARIO_DURATION}}
|
|
172
|
+
- Expected: {{SCENARIO_EXPECTED}}
|
|
173
|
+
- Actual: {{SCENARIO_ACTUAL}}
|
|
174
|
+
|
|
175
|
+
{{/EACH}}
|
|
176
|
+
|
|
177
|
+
**Example:**
|
|
178
|
+
```{{LANGUAGE}}
|
|
179
|
+
{{PERFORMANCE_TEST_EXAMPLE}}
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
{{/IF}}
|
|
183
|
+
|
|
184
|
+
{{#IF CHAOS_ENGINEERING}}
|
|
185
|
+
### Chaos Engineering
|
|
186
|
+
|
|
187
|
+
**Purpose:** Test system resilience to failures
|
|
188
|
+
|
|
189
|
+
**Tool:** {{CHAOS_TOOL}}
|
|
190
|
+
|
|
191
|
+
**Chaos Experiments:**
|
|
192
|
+
{{#EACH CHAOS_EXPERIMENT}}
|
|
193
|
+
#### {{EXPERIMENT_NAME}}
|
|
194
|
+
|
|
195
|
+
**Type:** {{EXPERIMENT_TYPE}}
|
|
196
|
+
|
|
197
|
+
**Hypothesis:** {{EXPERIMENT_HYPOTHESIS}}
|
|
198
|
+
|
|
199
|
+
**Method:**
|
|
200
|
+
{{#EACH EXPERIMENT_STEP}}
|
|
201
|
+
{{STEP_NUMBER}}. {{STEP_DESCRIPTION}}
|
|
202
|
+
{{/EACH}}
|
|
203
|
+
|
|
204
|
+
**Expected Behavior:** {{EXPERIMENT_EXPECTED}}
|
|
205
|
+
|
|
206
|
+
**Results:** {{EXPERIMENT_RESULTS}}
|
|
207
|
+
|
|
208
|
+
{{/EACH}}
|
|
209
|
+
|
|
210
|
+
**Common Scenarios:**
|
|
211
|
+
- Network latency injection
|
|
212
|
+
- Service failures
|
|
213
|
+
- Database connection failures
|
|
214
|
+
- CPU/memory exhaustion
|
|
215
|
+
- Disk space issues
|
|
216
|
+
|
|
217
|
+
**Safety Rules:**
|
|
218
|
+
- ✅ Run in staging first
|
|
219
|
+
- ✅ Have rollback plan ready
|
|
220
|
+
- ✅ Monitor metrics during experiments
|
|
221
|
+
- ✅ Limit blast radius
|
|
222
|
+
- ❌ Never run in production without approval
|
|
223
|
+
|
|
224
|
+
{{/IF}}
|
|
225
|
+
|
|
226
|
+
---
|
|
227
|
+
|
|
228
|
+
## 📁 Test Organization
|
|
229
|
+
|
|
230
|
+
### File Structure
|
|
231
|
+
|
|
232
|
+
**Pattern:** {{TEST_FILE_PATTERN}}
|
|
233
|
+
|
|
234
|
+
{{#IF COLOCATED}}
|
|
235
|
+
### Co-located Tests
|
|
236
|
+
|
|
237
|
+
```
|
|
238
|
+
src/
|
|
239
|
+
users/
|
|
240
|
+
user.service.ts
|
|
241
|
+
user.service.spec.ts ← Unit tests
|
|
242
|
+
user.controller.ts
|
|
243
|
+
user.controller.spec.ts
|
|
244
|
+
user.integration.spec.ts ← Integration tests
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
{{ELSE}}
|
|
248
|
+
### Separate Test Directory
|
|
249
|
+
|
|
250
|
+
```
|
|
251
|
+
src/
|
|
252
|
+
users/
|
|
253
|
+
user.service.ts
|
|
254
|
+
user.controller.ts
|
|
255
|
+
|
|
256
|
+
tests/
|
|
257
|
+
unit/
|
|
258
|
+
users/
|
|
259
|
+
user.service.test.ts
|
|
260
|
+
integration/
|
|
261
|
+
users/
|
|
262
|
+
user.integration.test.ts
|
|
263
|
+
e2e/
|
|
264
|
+
users/
|
|
265
|
+
user.e2e.test.ts
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
{{/IF}}
|
|
269
|
+
|
|
270
|
+
### Naming Conventions
|
|
271
|
+
|
|
272
|
+
**Test Files:**
|
|
273
|
+
```
|
|
274
|
+
{{TEST_FILE_NAMING_EXAMPLES}}
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
**Test Descriptions:**
|
|
278
|
+
```{{LANGUAGE}}
|
|
279
|
+
describe('{{DESCRIBE_EXAMPLE}}', () => {
|
|
280
|
+
describe('{{METHOD_NAME}}', () => {
|
|
281
|
+
it('should {{EXPECTED_BEHAVIOR}} when {{CONDITION}}', () => {
|
|
282
|
+
// test implementation
|
|
283
|
+
});
|
|
284
|
+
});
|
|
285
|
+
});
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
---
|
|
289
|
+
|
|
290
|
+
## 🎭 Mocking Strategy
|
|
291
|
+
|
|
292
|
+
### What to Mock
|
|
293
|
+
|
|
294
|
+
✅ **Always mock:**
|
|
295
|
+
- External APIs (third-party services)
|
|
296
|
+
- Payment gateways
|
|
297
|
+
- Email/SMS services
|
|
298
|
+
- File system operations (in unit tests)
|
|
299
|
+
- Time/Date functions
|
|
300
|
+
- Random number generators
|
|
301
|
+
|
|
302
|
+
❌ **Never mock:**
|
|
303
|
+
- Internal business logic
|
|
304
|
+
- Domain models
|
|
305
|
+
- Value objects
|
|
306
|
+
- Simple utilities
|
|
307
|
+
|
|
308
|
+
### Mocking Patterns
|
|
309
|
+
|
|
310
|
+
#### Database Mocking (Unit Tests)
|
|
311
|
+
|
|
312
|
+
```{{LANGUAGE}}
|
|
313
|
+
{{DATABASE_MOCK_EXAMPLE}}
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
#### External API Mocking
|
|
317
|
+
|
|
318
|
+
```{{LANGUAGE}}
|
|
319
|
+
{{EXTERNAL_API_MOCK_EXAMPLE}}
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
#### Time Mocking
|
|
323
|
+
|
|
324
|
+
```{{LANGUAGE}}
|
|
325
|
+
{{TIME_MOCK_EXAMPLE}}
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
---
|
|
329
|
+
|
|
330
|
+
## 🗄️ Test Database
|
|
331
|
+
|
|
332
|
+
### Strategy
|
|
333
|
+
|
|
334
|
+
{{TEST_DB_STRATEGY}}
|
|
335
|
+
|
|
336
|
+
{{#IF IN_MEMORY_DB}}
|
|
337
|
+
### In-Memory Database
|
|
338
|
+
|
|
339
|
+
**Type:** {{IN_MEMORY_DB_TYPE}}
|
|
340
|
+
|
|
341
|
+
**Benefits:**
|
|
342
|
+
- Fast test execution
|
|
343
|
+
- Isolated tests
|
|
344
|
+
- No cleanup needed
|
|
345
|
+
|
|
346
|
+
**Limitations:**
|
|
347
|
+
- Different DB from production
|
|
348
|
+
- Some features may not work identically
|
|
349
|
+
|
|
350
|
+
{{/IF}}
|
|
351
|
+
|
|
352
|
+
{{#IF DOCKER_TEST_DB}}
|
|
353
|
+
### Docker Test Database
|
|
354
|
+
|
|
355
|
+
**Image:** {{TEST_DB_IMAGE}}
|
|
356
|
+
|
|
357
|
+
**Tool:** {{TEST_CONTAINER_TOOL}}
|
|
358
|
+
|
|
359
|
+
**Benefits:**
|
|
360
|
+
- Same database as production
|
|
361
|
+
- Realistic testing
|
|
362
|
+
- Isolated per test run
|
|
363
|
+
|
|
364
|
+
**Setup:**
|
|
365
|
+
```bash
|
|
366
|
+
{{TEST_DB_SETUP_COMMAND}}
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
{{/IF}}
|
|
370
|
+
|
|
371
|
+
### Database Seeding
|
|
372
|
+
|
|
373
|
+
**Strategy:** {{DB_SEED_STRATEGY}}
|
|
374
|
+
|
|
375
|
+
```{{LANGUAGE}}
|
|
376
|
+
{{DB_SEED_EXAMPLE}}
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
### Database Cleanup
|
|
380
|
+
|
|
381
|
+
**When:** {{DB_CLEANUP_WHEN}}
|
|
382
|
+
|
|
383
|
+
```{{LANGUAGE}}
|
|
384
|
+
{{DB_CLEANUP_EXAMPLE}}
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
---
|
|
388
|
+
|
|
389
|
+
## 🏭 Test Data Factories
|
|
390
|
+
|
|
391
|
+
**Library:** {{FACTORY_LIBRARY}}
|
|
392
|
+
|
|
393
|
+
**Location:** `{{FACTORY_LOCATION}}`
|
|
394
|
+
|
|
395
|
+
### Factory Example
|
|
396
|
+
|
|
397
|
+
```{{LANGUAGE}}
|
|
398
|
+
{{FACTORY_EXAMPLE}}
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
### Usage
|
|
402
|
+
|
|
403
|
+
```{{LANGUAGE}}
|
|
404
|
+
{{FACTORY_USAGE_EXAMPLE}}
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
### Factory Rules
|
|
408
|
+
|
|
409
|
+
- ✅ Use factories for all test entities
|
|
410
|
+
- ✅ Provide sensible defaults
|
|
411
|
+
- ✅ Allow overrides for specific tests
|
|
412
|
+
- ✅ Keep factories DRY
|
|
413
|
+
- ❌ Don't hardcode test data in tests
|
|
414
|
+
|
|
415
|
+
---
|
|
416
|
+
|
|
417
|
+
## ✅ Test Structure
|
|
418
|
+
|
|
419
|
+
### AAA Pattern (Arrange, Act, Assert)
|
|
420
|
+
|
|
421
|
+
```{{LANGUAGE}}
|
|
422
|
+
{{AAA_PATTERN_EXAMPLE}}
|
|
423
|
+
```
|
|
424
|
+
|
|
425
|
+
### Given-When-Then (BDD)
|
|
426
|
+
|
|
427
|
+
```{{LANGUAGE}}
|
|
428
|
+
{{GIVEN_WHEN_THEN_EXAMPLE}}
|
|
429
|
+
```
|
|
430
|
+
|
|
431
|
+
---
|
|
432
|
+
|
|
433
|
+
## 🎯 Testing Best Practices
|
|
434
|
+
|
|
435
|
+
### General
|
|
436
|
+
|
|
437
|
+
- ✅ Tests should be independent (no test order dependency)
|
|
438
|
+
- ✅ Tests should be deterministic (same result every time)
|
|
439
|
+
- ✅ Tests should be fast (especially unit tests)
|
|
440
|
+
- ✅ Test names should clearly describe what they test
|
|
441
|
+
- ✅ One assertion per test (when possible)
|
|
442
|
+
- ✅ Test edge cases and error conditions
|
|
443
|
+
- ❌ Don't test implementation details
|
|
444
|
+
- ❌ Don't write tests that depend on each other
|
|
445
|
+
- ❌ Don't test external libraries
|
|
446
|
+
|
|
447
|
+
### Test Coverage
|
|
448
|
+
|
|
449
|
+
**Minimum Requirements:**
|
|
450
|
+
- Overall: {{MIN_COVERAGE}}%
|
|
451
|
+
- Services: {{SERVICE_COVERAGE}}%
|
|
452
|
+
- Controllers: {{CONTROLLER_COVERAGE}}%
|
|
453
|
+
- Repositories: {{REPOSITORY_COVERAGE}}%
|
|
454
|
+
- Utilities: {{UTILITY_COVERAGE}}%
|
|
455
|
+
|
|
456
|
+
**Exceptions (don't need 100% coverage):**
|
|
457
|
+
- Configuration files
|
|
458
|
+
- DTOs without logic
|
|
459
|
+
- Simple CRUD operations
|
|
460
|
+
- Type definitions
|
|
461
|
+
|
|
462
|
+
### What to Test
|
|
463
|
+
|
|
464
|
+
✅ **Do test:**
|
|
465
|
+
- Happy path (expected behavior)
|
|
466
|
+
- Error cases (validation, not found, unauthorized)
|
|
467
|
+
- Edge cases (empty arrays, null values, boundaries)
|
|
468
|
+
- Security (authentication, authorization)
|
|
469
|
+
- Business rules
|
|
470
|
+
- Data transformations
|
|
471
|
+
|
|
472
|
+
❌ **Don't test:**
|
|
473
|
+
- Framework behavior
|
|
474
|
+
- External libraries
|
|
475
|
+
- Getters/setters without logic
|
|
476
|
+
- Auto-generated code
|
|
477
|
+
|
|
478
|
+
---
|
|
479
|
+
|
|
480
|
+
## 🔧 Test Configuration
|
|
481
|
+
|
|
482
|
+
### Jest Configuration
|
|
483
|
+
|
|
484
|
+
**File:** `{{JEST_CONFIG_FILE}}`
|
|
485
|
+
|
|
486
|
+
```javascript
|
|
487
|
+
{{JEST_CONFIG_EXAMPLE}}
|
|
488
|
+
```
|
|
489
|
+
|
|
490
|
+
### Test Scripts
|
|
491
|
+
|
|
492
|
+
```json
|
|
493
|
+
{
|
|
494
|
+
"scripts": {
|
|
495
|
+
"test": "{{TEST_COMMAND}}",
|
|
496
|
+
"test:unit": "{{TEST_UNIT_COMMAND}}",
|
|
497
|
+
"test:integration": "{{TEST_INTEGRATION_COMMAND}}",
|
|
498
|
+
"test:e2e": "{{TEST_E2E_COMMAND}}",
|
|
499
|
+
"test:watch": "{{TEST_WATCH_COMMAND}}",
|
|
500
|
+
"test:coverage": "{{TEST_COVERAGE_COMMAND}}",
|
|
501
|
+
"test:debug": "{{TEST_DEBUG_COMMAND}}"
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
```
|
|
505
|
+
|
|
506
|
+
---
|
|
507
|
+
|
|
508
|
+
## 🚀 Running Tests
|
|
509
|
+
|
|
510
|
+
### Local Development
|
|
511
|
+
|
|
512
|
+
```bash
|
|
513
|
+
# Run all tests
|
|
514
|
+
{{RUN_ALL_TESTS}}
|
|
515
|
+
|
|
516
|
+
# Run tests in watch mode
|
|
517
|
+
{{RUN_TESTS_WATCH}}
|
|
518
|
+
|
|
519
|
+
# Run specific test file
|
|
520
|
+
{{RUN_SPECIFIC_TEST}}
|
|
521
|
+
|
|
522
|
+
# Run tests matching pattern
|
|
523
|
+
{{RUN_TESTS_PATTERN}}
|
|
524
|
+
|
|
525
|
+
# Run with coverage
|
|
526
|
+
{{RUN_TESTS_COVERAGE}}
|
|
527
|
+
|
|
528
|
+
# Debug tests
|
|
529
|
+
{{DEBUG_TESTS}}
|
|
530
|
+
```
|
|
531
|
+
|
|
532
|
+
### CI/CD
|
|
533
|
+
|
|
534
|
+
**Platform:** {{CICD_PLATFORM}}
|
|
535
|
+
|
|
536
|
+
**When tests run:**
|
|
537
|
+
{{#EACH TEST_TRIGGER}}
|
|
538
|
+
- {{TRIGGER_DESCRIPTION}}
|
|
539
|
+
{{/EACH}}
|
|
540
|
+
|
|
541
|
+
**Pipeline configuration:**
|
|
542
|
+
```yaml
|
|
543
|
+
{{CICD_TEST_CONFIG}}
|
|
544
|
+
```
|
|
545
|
+
|
|
546
|
+
---
|
|
547
|
+
|
|
548
|
+
## 📊 Coverage Reports
|
|
549
|
+
|
|
550
|
+
### Viewing Coverage
|
|
551
|
+
|
|
552
|
+
```bash
|
|
553
|
+
{{COVERAGE_COMMAND}}
|
|
554
|
+
```
|
|
555
|
+
|
|
556
|
+
**Coverage Report Location:** `{{COVERAGE_OUTPUT_DIR}}`
|
|
557
|
+
|
|
558
|
+
**Formats:**
|
|
559
|
+
- HTML: `{{COVERAGE_HTML_PATH}}`
|
|
560
|
+
- LCOV: `{{COVERAGE_LCOV_PATH}}`
|
|
561
|
+
- Text: Console output
|
|
562
|
+
|
|
563
|
+
### Coverage Thresholds
|
|
564
|
+
|
|
565
|
+
```javascript
|
|
566
|
+
{
|
|
567
|
+
"coverageThreshold": {
|
|
568
|
+
"global": {
|
|
569
|
+
"branches": {{BRANCH_COVERAGE}},
|
|
570
|
+
"functions": {{FUNCTION_COVERAGE}},
|
|
571
|
+
"lines": {{LINE_COVERAGE}},
|
|
572
|
+
"statements": {{STATEMENT_COVERAGE}}
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
```
|
|
577
|
+
|
|
578
|
+
**Enforcement:** Tests fail if coverage drops below thresholds
|
|
579
|
+
|
|
580
|
+
---
|
|
581
|
+
|
|
582
|
+
## 🧬 Test Examples
|
|
583
|
+
|
|
584
|
+
### Service Test
|
|
585
|
+
|
|
586
|
+
```{{LANGUAGE}}
|
|
587
|
+
{{SERVICE_TEST_FULL_EXAMPLE}}
|
|
588
|
+
```
|
|
589
|
+
|
|
590
|
+
### Controller Test
|
|
591
|
+
|
|
592
|
+
```{{LANGUAGE}}
|
|
593
|
+
{{CONTROLLER_TEST_FULL_EXAMPLE}}
|
|
594
|
+
```
|
|
595
|
+
|
|
596
|
+
### Repository Test
|
|
597
|
+
|
|
598
|
+
```{{LANGUAGE}}
|
|
599
|
+
{{REPOSITORY_TEST_FULL_EXAMPLE}}
|
|
600
|
+
```
|
|
601
|
+
|
|
602
|
+
### E2E Test
|
|
603
|
+
|
|
604
|
+
```{{LANGUAGE}}
|
|
605
|
+
{{E2E_TEST_FULL_EXAMPLE}}
|
|
606
|
+
```
|
|
607
|
+
|
|
608
|
+
---
|
|
609
|
+
|
|
610
|
+
## 🔒 Testing Security
|
|
611
|
+
|
|
612
|
+
### Authentication Tests
|
|
613
|
+
|
|
614
|
+
```{{LANGUAGE}}
|
|
615
|
+
{{AUTH_TEST_EXAMPLE}}
|
|
616
|
+
```
|
|
617
|
+
|
|
618
|
+
### Authorization Tests
|
|
619
|
+
|
|
620
|
+
```{{LANGUAGE}}
|
|
621
|
+
{{AUTHZ_TEST_EXAMPLE}}
|
|
622
|
+
```
|
|
623
|
+
|
|
624
|
+
### Input Validation Tests
|
|
625
|
+
|
|
626
|
+
```{{LANGUAGE}}
|
|
627
|
+
{{INPUT_VALIDATION_TEST_EXAMPLE}}
|
|
628
|
+
```
|
|
629
|
+
|
|
630
|
+
---
|
|
631
|
+
|
|
632
|
+
## 🐛 Debugging Tests
|
|
633
|
+
|
|
634
|
+
### Debug Configuration
|
|
635
|
+
|
|
636
|
+
**VS Code:**
|
|
637
|
+
```json
|
|
638
|
+
{{VSCODE_DEBUG_CONFIG}}
|
|
639
|
+
```
|
|
640
|
+
|
|
641
|
+
### Debug Commands
|
|
642
|
+
|
|
643
|
+
```bash
|
|
644
|
+
# Debug specific test
|
|
645
|
+
{{DEBUG_SPECIFIC_TEST}}
|
|
646
|
+
|
|
647
|
+
# Debug with breakpoints
|
|
648
|
+
{{DEBUG_WITH_BREAKPOINTS}}
|
|
649
|
+
```
|
|
650
|
+
|
|
651
|
+
---
|
|
652
|
+
|
|
653
|
+
## 📝 Test Documentation
|
|
654
|
+
|
|
655
|
+
### When to Document Tests
|
|
656
|
+
|
|
657
|
+
- ✅ Complex test setups
|
|
658
|
+
- ✅ Non-obvious mocking strategies
|
|
659
|
+
- ✅ Performance test configurations
|
|
660
|
+
- ✅ Flaky test explanations
|
|
661
|
+
|
|
662
|
+
### Example
|
|
663
|
+
|
|
664
|
+
```{{LANGUAGE}}
|
|
665
|
+
/**
|
|
666
|
+
* Tests the order calculation logic with multiple edge cases.
|
|
667
|
+
*
|
|
668
|
+
* This test verifies:
|
|
669
|
+
* 1. Basic order total calculation
|
|
670
|
+
* 2. Tax application
|
|
671
|
+
* 3. Discount code validation
|
|
672
|
+
* 4. Edge case: zero-price items
|
|
673
|
+
* 5. Edge case: 100% discount
|
|
674
|
+
*
|
|
675
|
+
* Mock strategy:
|
|
676
|
+
* - DiscountService is mocked to avoid external API calls
|
|
677
|
+
* - TaxService uses real implementation for accuracy
|
|
678
|
+
*/
|
|
679
|
+
describe('Order Total Calculation', () => {
|
|
680
|
+
// tests...
|
|
681
|
+
});
|
|
682
|
+
```
|
|
683
|
+
|
|
684
|
+
---
|
|
685
|
+
|
|
686
|
+
## 🚨 Continuous Testing
|
|
687
|
+
|
|
688
|
+
### Pre-commit Hooks
|
|
689
|
+
|
|
690
|
+
```bash
|
|
691
|
+
{{PRE_COMMIT_HOOK_CONFIG}}
|
|
692
|
+
```
|
|
693
|
+
|
|
694
|
+
**Runs:**
|
|
695
|
+
- Linting
|
|
696
|
+
- Unit tests
|
|
697
|
+
- Type checking
|
|
698
|
+
|
|
699
|
+
### Pre-push Hooks
|
|
700
|
+
|
|
701
|
+
```bash
|
|
702
|
+
{{PRE_PUSH_HOOK_CONFIG}}
|
|
703
|
+
```
|
|
704
|
+
|
|
705
|
+
**Runs:**
|
|
706
|
+
- Full test suite
|
|
707
|
+
- Coverage check
|
|
708
|
+
|
|
709
|
+
---
|
|
710
|
+
|
|
711
|
+
## 📈 Test Metrics
|
|
712
|
+
|
|
713
|
+
### Tracked Metrics
|
|
714
|
+
|
|
715
|
+
- Test count (unit, integration, e2e)
|
|
716
|
+
- Test execution time
|
|
717
|
+
- Code coverage (overall, per type)
|
|
718
|
+
- Flaky test rate
|
|
719
|
+
- Test failure rate
|
|
720
|
+
|
|
721
|
+
### Goals
|
|
722
|
+
|
|
723
|
+
{{#EACH TEST_GOAL}}
|
|
724
|
+
- **{{GOAL_NAME}}**: {{GOAL_TARGET}}
|
|
725
|
+
{{/EACH}}
|
|
726
|
+
|
|
727
|
+
---
|
|
728
|
+
|
|
729
|
+
## 🔄 Test Maintenance
|
|
730
|
+
|
|
731
|
+
### Regular Tasks
|
|
732
|
+
|
|
733
|
+
- ✅ Update tests when code changes
|
|
734
|
+
- ✅ Remove obsolete tests
|
|
735
|
+
- ✅ Fix flaky tests immediately
|
|
736
|
+
- ✅ Refactor tests alongside code
|
|
737
|
+
- ✅ Update test data periodically
|
|
738
|
+
|
|
739
|
+
### Code Review Checklist
|
|
740
|
+
|
|
741
|
+
- [ ] New code has tests
|
|
742
|
+
- [ ] Tests are meaningful (not just for coverage)
|
|
743
|
+
- [ ] Tests pass locally
|
|
744
|
+
- [ ] Coverage meets threshold
|
|
745
|
+
- [ ] No skipped/disabled tests (without reason)
|
|
746
|
+
- [ ] Test names are descriptive
|
|
747
|
+
|
|
748
|
+
---
|
|
749
|
+
|
|
750
|
+
## 📚 Resources
|
|
751
|
+
|
|
752
|
+
{{#EACH TESTING_RESOURCE}}
|
|
753
|
+
- [{{RESOURCE_NAME}}]({{RESOURCE_URL}})
|
|
754
|
+
{{/EACH}}
|
|
755
|
+
|
|
756
|
+
---
|
|
757
|
+
|
|
758
|
+
**Document Version:** 1.0
|
|
759
|
+
|
|
760
|
+
**Last Updated:** {{GENERATION_DATE}}
|
|
761
|
+
|
|
762
|
+
**Generated by:** AI Flow v1.0.0
|