フリー問題

Salesforce Certified Platform Developer II のフリー問題 14 / 20 問目

問題文

A pharmacy chain has a class that asks an external interaction-checking service about a prescription over HTTP. The unit test fails because the callout is not allowed while a test is running. Which approach lets the test exercise the class?

選択肢

  1. Implement HttpCalloutMock to build the response, and register that instance with Test.setMock before the code under test runs, because the registration is what makes the platform hand the fake response to the callout.
  2. Wrap the callout in a condition that skips it when isRunningTest returns true, so the rest of the method still runs, and the response path stays uncovered.
  3. Move the callout into a method that runs asynchronously and invoke it between startTest and stopTest, because asynchronous work inside a test is permitted to reach an external service.
  4. Add the service's endpoint to remote site settings so the test is allowed to reach the real service, and the real answer is what the test asserts on.

解答・解説を確認するには

正解と解説の確認、回答の記録には無料登録が必要です。登録すると演習モードでフリー問題に回答し、正誤と解説をその場で確認できます。