I have one apex class in which I am calling one webservice of one of my managed package installed in my org. When I am writing the test class for my apex class, it is throwing the error

callout not allowed from test method

Can somebody help me on this?

  • I think Salesforce needs to support Mocking managed API so that managed packages can be treated as a black box. – Zhenxin Wang Jun 29 '16 at 20:23
  • What does you're response look like? What does it look like when you deserilize it? You would be able to assert your conditions there – EricSSH Jun 30 '16 at 5:24

From the documentation

By default, test methods don’t support Web service callouts and tests that perform Web service callouts are skipped. To prevent tests from being skipped and to increase code coverage, Apex provides the built-in WebServiceMock interface and the Test.setMock method that you can use to receive fake responses in a test method.

Take a look at the link below and implement the WebServiceMock interface interface for this.


  • Thanks for the reply. But I don't know how to handle the web service that is part of managed package. Because I am calling a web service that is part of a managed package. Is there something that needs to be taken care of from managed package side. – Nitish Singhal Oct 9 '14 at 6:43

You need to Mock the HTTP response. The official Apex documentation has plenty of examples doing that. A good starting point is Testing HTTP Callouts .


http://sfdc.arrowpointe.com/2009/05/01/testing-http-callouts/ Here is a beautiful post written by Scott Hemmeter. I hope it will help you sorting out your problem.

  • This approach is outdated. Callouts should be tested by mocking the response. – Alexander Johannes Oct 8 '14 at 12:16
  • Thanks Alexander could you please guide us to a tutorial where we can learn about Callouts testing by mocking the response. Sorry i saw your post now. – Shanker Paudel Oct 8 '14 at 12:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.