開発者は、REST API を使用して外部システムを呼び出す Apex コードを作成しました。 コードが意図したとおりに動作していることを証明するために、開発者はどのようにテストを記述すればよいでしょうか?
正解: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.