As you know, by default, test methods don’t support web service callouts, and tests that perform web service callouts fail. Apex provides the built-in WebServiceMock interface and the Test.setMock method to prevent tests from failing. So, today, we are back with yet another Salesforce solution. Let’s know how to create a mock callout to test the Apex rest callout in Salesforce.
Further, the Apex test class will not let us conduct an HTTP callout. Hence, you cannot test external APIs. But, Apex does have an interface called HttpCalloutMock for standard callout tests.
Let’s get started!
Code
Screenshot
Conclusion
There you have it! The perfect solution that allows you to create a mock callout to test the apex rest callout in Salesforce. We hope that you liked this blog and it was helpful for you. Also, if you try out this solution for your business, then don’t forget to share your experiences with us. We will be back with another Salesforce solution next week so stay tuned. Till then, happy learning!