Valid PDI Dumps shared by ExamDiscuss.com for Helping Passing PDI Exam! ExamDiscuss.com now offer the newest PDI exam dumps, the ExamDiscuss.com PDI exam questions have been updated and answers have been corrected get the newest ExamDiscuss.com PDI dumps with Test Engine here:
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?
Correct Answer: D
When writing tests for Apex code that performs callouts to external services, Salesforce requires that callouts are mocked to ensure that tests do not depend on external systems and to allow for consistent and predictable test results. Correct Option: Option D: Write a class that implements HttpCalloutMock. True. To test HTTP callouts, you implement the HttpCalloutMock interface and provide a fake response for the HTTP request. This mock response is then used in your test methods to simulate the callout. The test method uses Test.setMock to set the mock class. WebServiceMock is used for testing SOAP callouts, not REST (HTTP) callouts. Since the code uses REST API, HttpCalloutMock is appropriate. HttpCalloutMock is an interface, not a class. You cannot extend an interface; you implement it. The correct approach is to implement the HttpCalloutMock interface. Reference: Testing HTTP Callouts by Implementing HttpCalloutMock Incorrect Options: Option A & C: Write a class that implements or extends WebServiceMock. False. Testing SOAP Callouts Option B: Write a class that extends HttpCalloutMock. False. Interface vs. Class Conclusion: To properly test REST API callouts in Apex, you should write a class that implements HttpCalloutMock and use it in your test methods.