Apex Callouts and Test.setMock: Testing an External REST Integration Without Live Credentials
0 reputation · 09 Aug 2025, 20:23 UTC
An Apex service class integrates with an external REST API through HttpRequest and HttpResponse, and the integration needs test coverage in an environment where production credentials and live endpoints are unavailable. The documented mechanism is Test.setMock with an HttpCalloutMock implementation, which intercepts the callout so no real request leaves the org.
The unresolved design point is how to structure the mock layer when the service contacts more than one endpoint, or when different methods expect different response payloads. It is also unclear which runtime rules remain in force once a mock is registered, such as whether endpoints must still be whitelisted and whether test-context callouts consume the organization's concurrent callout or API limits.
- Should a single
HttpCalloutMockclass branch on the request endpoint and method, or should each callout path receive its own mock implementation? - Do mocked callouts still require Remote Site Settings entries, and do they count against org callout limits during test execution?