Integration testing requires coordinating both sides.
Levels:
1. Unit tests of integration code.
- Apex tests with
Test.setMock(HttpCalloutMock.class)for outbound. - Mock external responses.
- Test happy / error paths.
2. Component tests.
- Salesforce side: Apex callout to mock external.
- External side: receive Salesforce calls; respond.
3. End-to-end integration tests.
- Salesforce + external system live.
- Trigger real flow; observe both sides.
- Often manual or UI automation.
4. Contract testing.
- Define API contract.
- Both sides test against contract.
- Tools: Pact, Postman.
5. UAT.
- Real users; real data; real systems.
Test environments:
- Salesforce sandbox + external test system.
- Mock services for external when test instance unavailable.
- Contract servers for contract testing.
Test scenarios:
- Success path — happy data, normal flow.
- Failure of external — external down; Salesforce should handle gracefully.
- Slow response — timeout handling.
- Invalid data — external returns malformed data.
- Authentication failure — token expired.
- Rate limiting — external throttles.
- Eventual consistency — async flows.
Common pitfalls:
- Only testing happy path — failures are common in production; not tested.
- No mocking — tests dependent on external availability; flaky.
- Manual integration tests — slow, skipped under deadline pressure.
- No contract — Salesforce + external diverge; integration breaks silently.
Architecture for testability:
- Wrap external dependencies in interfaces / Apex classes.
- Mockable via dependency injection.
- Configurable via Custom Metadata for endpoint switching.
- Logging all integration events for forensics.
Senior QA insight: integrations break in production — they're a top source of incidents. Comprehensive integration testing pays back.
The senior framing: integrations are the most fragile parts of Salesforce systems. Test them most carefully.
