Why do methods defined as testmethod do not support web service callouts?

299    Asked by AndrewJenkins in Salesforce , Asked on Sep 22, 2022

 have been struggling with this error for a few days now. I get this error every time I try to run a test for a method that has an httpCallout. I followed the architecture from http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_restful_http_testing_httpcalloutmock.htm, but to no avail. I thought it could be something I was messing up in my code, so I copied all three of the classes from the documentation, and I am still getting the error when I try to run the test. All of the classes are on Salesforce API 29. Has anyone run into this before?

Answered by Andrea Bailey

The answer to your question - why methods defined as testmethod do not support web service callouts is - You need to call Test.setMock(...) in your test class once you've implemented the required interfaces to prevent this particular error message. You shouldn't need to use Test.isRunningTest() to test your call outs (and doing so gives you untestable code).

Your Answer


Parent Categories