nerdexam
Salesforce

PDI · Question #17

A developer wrote Apex code that calls out to an external system. How should a developer write the test to provide test coverage?

The correct answer is B. Write a class that implements the HTTPCalloutMock interface. To provide test coverage for Apex code that makes HTTP callouts to an external system, a developer should write a mock class that implements the HttpCalloutMock interface.

Submitted by anjalisingh· Apr 18, 2026Testing, Debugging, and Deployment

Question

A developer wrote Apex code that calls out to an external system. How should a developer write the test to provide test coverage?

Options

  • AWrite a class that extends HTTPCalloutMock.
  • BWrite a class that implements the HTTPCalloutMock interface.
  • CWrite a class that implements the WebserviceMock interface.
  • DWrite a class that extends WebserviceMock

How the community answered

(41 responses)
  • A
    2% (1)
  • B
    95% (39)
  • D
    2% (1)

Why each option

To provide test coverage for Apex code that makes HTTP callouts to an external system, a developer should write a mock class that implements the `HttpCalloutMock` interface.

AWrite a class that extends HTTPCalloutMock.

`HttpCalloutMock` is an interface, not a class, and therefore must be implemented by a class, not extended.

BWrite a class that implements the HTTPCalloutMock interface.Correct

Implementing the `HttpCalloutMock` interface is the standard and required approach for simulating responses from external HTTP callouts in Apex tests, preventing actual network calls and ensuring reliable and fast test execution.

CWrite a class that implements the WebserviceMock interface.

The `WebserviceMock` interface is specifically used for mocking WSDL-based web service callouts, not for HTTP REST callouts.

DWrite a class that extends WebserviceMock

`WebserviceMock` is an interface, not a class, and is intended for WSDL-based web service callouts, making it inappropriate for testing HTTP REST callouts.

Concept tested: Mocking HTTP callouts in Apex tests

Source: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_callouts_http_testing.htm

Topics

#Apex Testing#Callout Mocking#HTTPCalloutMock#Unit Testing

Community Discussion

No community discussion yet for this question.

Full PDI Practice