You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: expand sf-e2e-runner agent from 4.4KB to 10.6KB
Add user journey mapping template, test data architecture guidance,
9 test dimensions (bulk 200/10K, permissions, async chains, Platform
Events, error recovery), flaky test diagnosis table (8 root causes),
CI integration stages, and E2E test organization conventions.
Design a `TestDataFactory` that builds the complete object hierarchy for your E2E scenarios. This is the foundation β poor test data is the #1 cause of flaky E2E tests.
- Use `@TestSetup` for the shared base hierarchy (runs once per test class)
76
+
- Use `TestDataFactory` methods for scenario-specific variations
77
+
- Never use `SeeAllData=true`
78
+
- Never hardcode record IDs β query by Name or ExternalId
79
+
- Create test users in `@TestSetup` with appropriate profiles/permission sets
39
80
40
-
For each scenario, define: happy path, edge cases (null inputs, 0 records, 200-record bulk), and governor limit boundaries.
81
+
**Data volume targets:**
41
82
42
-
### Step 2: Create Apex E2E Tests
83
+
| Context | Volume | Why |
84
+
|---------|--------|-----|
85
+
| Unit test | 1-5 records | Fast, isolated |
86
+
| E2E trigger test | 200 records | Trigger context limit |
87
+
| E2E batch test | 2,000+ records | Batch chunk processing |
88
+
| E2E bulk load | 10,000+ records | Governor limit stress test (use Batch Apex in test) |
43
89
44
-
Use `@TestSetup` for shared data, `TestDataFactory` for all record creation, and `Test.startTest()`/`Test.stopTest()` to reset governor limits around the code under test.
90
+
### Step 3: Create Apex E2E Tests
91
+
92
+
Use `Test.startTest()`/`Test.stopTest()` to reset governor limits around the code under test. This is critical for E2E tests where setup consumes significant limits.
93
+
94
+
**Key patterns for E2E:**
45
95
46
-
Key patterns:
47
96
-`@TestSetup` β create the full data hierarchy once per class
48
97
-`HttpCalloutMock` / `Test.setMock()` β mock all external callouts
49
98
-`Test.getEventBus().deliver()` β force synchronous Platform Event delivery
50
99
-`System.runAs()` β test permission-sensitive operations
- Multi-user permission testing with `System.runAs()`
108
+
- Performance assertions (SOQL count, DML count within bounds)
53
109
54
-
### Step 3: Create LWC Integration Tests
110
+
### Step 4: Create LWC Integration Tests
55
111
56
-
Use Jest with `@salesforce/apex` mocks. For imperative Apex calls use `jest.fn()` + `mockResolvedValue`. For `@wire`-decorated properties use `createApexTestWireAdapter` from `@salesforce/sfdx-lwc-jest`.
112
+
Use Jest with `@salesforce/apex` mocks for LWC integration testing. E2E LWC tests differ from unit tests in that they exercise multi-component interaction and full data flow.
57
113
58
-
Always clean the DOM in `afterEach` and call `jest.clearAllMocks()`. See skill `sf-lwc-testing` for full wire adapter patterns.
114
+
**E2E LWC test patterns:**
115
+
- Parent-child component communication via events
116
+
- Multiple wire adapters loading in sequence
117
+
- Error state propagation (Apex throws β component shows error)
118
+
- Navigation after successful operations (`NavigationMixin`)
119
+
- Toast notification assertions after DML operations
59
120
60
-
Run LWC tests:
121
+
Always clean the DOM in `afterEach` and call `jest.clearAllMocks()`. See skill `sf-lwc-testing` for complete wire adapter and event testing patterns.
61
122
62
123
```bash
63
-
npm run test:unit
124
+
# Run LWC tests with coverage
64
125
npm run test:unit -- --coverage
126
+
127
+
# Run specific test file
128
+
npx jest force-app/main/default/lwc/myComponent/__tests__/myComponent.test.js
65
129
```
66
130
67
-
### Step 4: Execute and Validate
131
+
### Step 5: Execute and Validate
132
+
133
+
**Local execution:**
68
134
69
135
```bash
70
136
# Run all Apex tests with coverage
@@ -73,33 +139,105 @@ sf apex run test --test-level RunLocalTests --code-coverage --result-format huma
73
139
# Run a specific E2E class
74
140
sf apex run test --class-names "OrderProcessE2ETest" --result-format human --wait 10
75
141
76
-
# Check detailed results
77
-
sf apex get test --test-run-id <id> --result-format human
142
+
# Run with RunRelevantTests (Spring '26 / API 66.0) for faster CI
sf org create scratch -f config/project-scratch-def.json -a e2e-test -d 7
151
+
152
+
# Push source and run all tests
153
+
sf project deploy start --target-org e2e-test
154
+
sf apex run test --test-level RunLocalTests --code-coverage --result-format human --target-org e2e-test --wait 15
78
155
```
79
156
80
-
Run in scratch org for isolation. For CI, run multiple times at different hours to detect flakiness caused by async platform-side timing. Target: code coverage > 85% (75% minimum), all critical-path tests passing, zero flaky tests.
0 commit comments