Salesforce Platform Developer I (legacy) — Question 259
A developer wrote Apex code that calls out to an external system using REST API.
How should a developer write the test to prove the code is working as intended?
Answer options
- A. Write a class that extends WebServiceMock.
- B. Write a class that implements HTTPCalloutMock.
- C. Write a class that extends HTTPCalloutMock.
- D. Write a class that implements WebServiceMock.
Correct answer: C
Explanation
The correct answer is C because extending HTTPCalloutMock allows the developer to simulate responses for HTTP callouts in tests. Options A and D are incorrect as they pertain to WebServiceMock, which is not suitable for REST API callouts. Option B is also incorrect because while it implements HTTPCalloutMock, it does not extend it, which is necessary for creating a mock response.