Test Automation Strategy
Quick Anti-Pattern Detection:
- Ice cream cone (many E2E, few unit) → Invert to pyramid
- Slow tests (> 10 min suite) → Parallelize, mock external deps
- Flaky tests → Fix timing, isolate data, or quarantine
- Brittle selectors → Use data-testid, semantic locators
Quick Reference Card
When to Use
- Building new automation framework
- Improving existing test efficiency
- Reducing flaky test burden
- Optimizing CI/CD pipeline speed
Anti-Patterns to Detect
| Problem |
Symptom |
Fix |
| Ice cream cone |
80% E2E, 10% unit |
Invert pyramid |
| Slow suite |
30+ min CI |
Parallelize, prune |
| Flaky tests |
Random failures |
Quarantine, fix timing |
| Coupled tests |
Order-dependent |
Isolate data |
| Brittle selectors |
Break on CSS change |
Use data-testid |
CI/CD Integration
name: Test Pipeline
on: [push, pull_request]
jobs:
unit-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm ci
- run: npm run test:unit -- --coverage
timeout-minutes: 5
- uses: codecov/codecov-action@v3
integration-tests:
needs: unit-tests
runs-on: ubuntu-latest
services:
postgres:
image: postgres:15
steps:
- run: npm run test:integration
timeout-minutes: 10
e2e-tests:
needs: integration-tests
runs-on: ubuntu-latest
steps:
- run: npx playwright test
timeout-minutes: 15
Flaky Test Management
// Quarantine flaky tests
describe.skip('Quarantined - INC-123', () => {
test('flaky test awaiting fix', () => { /* ... */ });
});
// Agent-assisted stabilization
await Task("Fix Flaky Tests", {
tests: quarantinedTests,
analysis: ['timing-issues', 'data-isolation', 'race-conditions'],
strategies: ['add-waits', 'isolate-fixtures', 'mock-externals']
}, "qe-flaky-test-hunter");
Agent-Assisted Automation
// Generate tests following pyramid
await Task("Generate Test Suite", {
sourceCode: 'src/',
pyramid: { unit: 70, integration: 20, e2e: 10 },
patterns: ['page-object', 'builder', 'factory'],
framework: 'jest'
}, "qe-test-generator");
// Optimize test execution
await Task("Optimize Suite", {
algorithm: 'johnson-lindenstrauss',
targetReduction: 0.3,
maintainCoverage: 0.95
}, "qe-regression-risk-analyzer");
// Analyze flaky patterns
await Task("Flaky Analysis", {
testHistory: 'last-30-days',
detectPatterns: ['timing', 'data', 'environment'],
recommend: 'stabilization-strategy'
}, "qe-flaky-test-hunter");
Agent Coordination Hints
Memory Namespace
aqe/automation/
├── test-pyramid/* - Coverage by layer
├── page-objects/* - Shared page objects
├── flaky-registry/* - Quarantined tests
└── execution-metrics/* - Suite performance data
Fleet Coordination
const automationFleet = await FleetManager.coordinate({
strategy: 'test-automation',
agents: [
'qe-test-generator', // Generate pyramid-compliant tests
'qe-test-executor', // Parallel execution
'qe-coverage-analyzer', // Coverage gaps
'qe-flaky-test-hunter', // Flaky detection
'qe-regression-risk-analyzer' // Smart selection
],
topology: 'hierarchical'
});
Related Skills
Remember
With Agents: Agents generate pyramid-compliant tests, detect flaky patterns, optimize execution time, and maintain test infrastructure. Use agents to scale automation quality.
Gotchas
- Agent generates 80% E2E tests and 20% unit tests (inverted pyramid) — explicitly enforce 70/20/10 ratio
- Page Object Model tests become brittle when selectors change — prefer data-testid attributes over CSS selectors
- Flaky tests quarantined but never fixed is technical debt — set a 2-week SLA to fix or delete
- Agent treats test code as second-class — test code needs the same review standards as production code
- Parallel test execution requires test isolation — shared state between tests causes non-deterministic failures
1---
2name: test-automation-strategy
3description: "Design and implement effective test automation with proper pyramid, patterns, and CI/CD integration. Use when building automation frameworks or improving test efficiency."
4category: testing-methodologies
5priority: high
6tokenEstimate: 1000
7agents: [qe-test-generator, qe-test-executor, qe-coverage-analyzer, qe-flaky-test-hunter, qe-regression-risk-analyzer]
8implementation_status: optimized
9optimization_version: 1.0
10last_optimized: 2025-12-02
11dependencies: []
12quick_reference_card: true
13tags: [automation, test-pyramid, page-object, first-principles, ci-cd, flaky-tests]
14trust_tier: 3
15validation:
16 schema_path: schemas/output.json
17 validator_path: scripts/validate-config.json
18 eval_path: evals/test-automation-strategy.yaml
19---
20
21# Test Automation Strategy
22
23<default_to_action>
24When designing or improving test automation:
251. DETECT anti-patterns: Ice cream cone? Slow suite? Flaky tests?
262. USE patterns: Page Object Model, Builder pattern, Factory pattern
273. INTEGRATE in CI/CD: Every commit runs tests, fail fast
284. MANAGE flaky tests: Quarantine, fix, or delete - never ignore
29
30**Quick Anti-Pattern Detection:**
31- Ice cream cone (many E2E, few unit) → Invert to pyramid
32- Slow tests (> 10 min suite) → Parallelize, mock external deps
33- Flaky tests → Fix timing, isolate data, or quarantine
34- Brittle selectors → Use data-testid, semantic locators
35</default_to_action>
36
37## Quick Reference Card
38
39### When to Use
40- Building new automation framework
41- Improving existing test efficiency
42- Reducing flaky test burden
43- Optimizing CI/CD pipeline speed
44
45### Anti-Patterns to Detect
46| Problem | Symptom | Fix |
47|---------|---------|-----|
48| Ice cream cone | 80% E2E, 10% unit | Invert pyramid |
49| Slow suite | 30+ min CI | Parallelize, prune |
50| Flaky tests | Random failures | Quarantine, fix timing |
51| Coupled tests | Order-dependent | Isolate data |
52| Brittle selectors | Break on CSS change | Use data-testid |
53
54---
55
56## CI/CD Integration
57
58```yaml
59name: Test Pipeline
60on: [push, pull_request]
61
62jobs:
63 unit-tests:
64 runs-on: ubuntu-latest
65 steps:
66 - uses: actions/checkout@v4
67 - run: npm ci
68 - run: npm run test:unit -- --coverage
69 timeout-minutes: 5
70 - uses: codecov/codecov-action@v3
71
72 integration-tests:
73 needs: unit-tests
74 runs-on: ubuntu-latest
75 services:
76 postgres:
77 image: postgres:15
78 steps:
79 - run: npm run test:integration
80 timeout-minutes: 10
81
82 e2e-tests:
83 needs: integration-tests
84 runs-on: ubuntu-latest
85 steps:
86 - run: npx playwright test
87 timeout-minutes: 15
88```
89
90---
91
92## Flaky Test Management
93
94```typescript
95// Quarantine flaky tests
96describe.skip('Quarantined - INC-123', () => {
97 test('flaky test awaiting fix', () => { /* ... */ });
98});
99
100// Agent-assisted stabilization
101await Task("Fix Flaky Tests", {
102 tests: quarantinedTests,
103 analysis: ['timing-issues', 'data-isolation', 'race-conditions'],
104 strategies: ['add-waits', 'isolate-fixtures', 'mock-externals']
105}, "qe-flaky-test-hunter");
106```
107
108---
109
110## Agent-Assisted Automation
111
112```typescript
113// Generate tests following pyramid
114await Task("Generate Test Suite", {
115 sourceCode: 'src/',
116 pyramid: { unit: 70, integration: 20, e2e: 10 },
117 patterns: ['page-object', 'builder', 'factory'],
118 framework: 'jest'
119}, "qe-test-generator");
120
121// Optimize test execution
122await Task("Optimize Suite", {
123 algorithm: 'johnson-lindenstrauss',
124 targetReduction: 0.3,
125 maintainCoverage: 0.95
126}, "qe-regression-risk-analyzer");
127
128// Analyze flaky patterns
129await Task("Flaky Analysis", {
130 testHistory: 'last-30-days',
131 detectPatterns: ['timing', 'data', 'environment'],
132 recommend: 'stabilization-strategy'
133}, "qe-flaky-test-hunter");
134```
135
136---
137
138## Agent Coordination Hints
139
140### Memory Namespace
141```
142aqe/automation/
143├── test-pyramid/* - Coverage by layer
144├── page-objects/* - Shared page objects
145├── flaky-registry/* - Quarantined tests
146└── execution-metrics/* - Suite performance data
147```
148
149### Fleet Coordination
150```typescript
151const automationFleet = await FleetManager.coordinate({
152 strategy: 'test-automation',
153 agents: [
154 'qe-test-generator', // Generate pyramid-compliant tests
155 'qe-test-executor', // Parallel execution
156 'qe-coverage-analyzer', // Coverage gaps
157 'qe-flaky-test-hunter', // Flaky detection
158 'qe-regression-risk-analyzer' // Smart selection
159 ],
160 topology: 'hierarchical'
161});
162```
163
164---
165
166## Related Skills
167- [tdd-london-chicago](../tdd-london-chicago/) - TDD for unit tests
168- [api-testing-patterns](../api-testing-patterns/) - Integration patterns
169- [cicd-pipeline-qe-orchestrator](../cicd-pipeline-qe-orchestrator/) - Pipeline integration
170- [shift-left-testing](../shift-left-testing/) - Early automation
171
172---
173
174## Remember
175
176**With Agents:** Agents generate pyramid-compliant tests, detect flaky patterns, optimize execution time, and maintain test infrastructure. Use agents to scale automation quality.
177
178## Gotchas
179
180- Agent generates 80% E2E tests and 20% unit tests (inverted pyramid) — explicitly enforce 70/20/10 ratio
181- Page Object Model tests become brittle when selectors change — prefer data-testid attributes over CSS selectors
182- Flaky tests quarantined but never fixed is technical debt — set a 2-week SLA to fix or delete
183- Agent treats test code as second-class — test code needs the same review standards as production code
184- Parallel test execution requires test isolation — shared state between tests causes non-deterministic failures