function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SuvraSuvra 

System.TypeException: Testmethods do not support webservice callouts

Hi,

 

While Running a testmethod, I am getting the exception "System.TypeException: Testmethods do not support webservice callouts". This testmethod is for testing a trigger, which is calling the Google API service for Latitude and Lonitude Conversion. I am using Salesforce API version 15.0

 

What can be the alternative way? Please help..

 

Thanks in advance,

Suvra

Best Answer chosen by Admin (Salesforce Developers) 
SuvraSuvra

Hello all,

 

Web Service Callouts are not supported by test methods. So, in web service callouts we can't get any code coverage. But we can increase the code coverage to a maximum level by modularizing the code.

Say, before making the callout we'll be preparing the request and after receiving output response will be formed.

So, we can have three separate methods for this purpose..

1. for Request forming

2. for Callout - this method will just contain the line which is actually making the call

3. for forming Response.

 

Now, in test method #1 will get covered, #2 and #3 will be left uncovered. Here we can form manual response and call method #3. This way only minimum no. of lines will be left untouched and coverage will be increased.

 

 Thanks and Regards,

 Suvra

All Answers

DDayDDay

Hello,

 

I'm running into the same issue. I have a bunch of methods using HttpRequest to call a web service and won't be able to achieve 75%+ test coverage if I can't test any of these methods.

 

 What is a solution / alternative to testing these methods?

 

Thanks,

Dan

SergiSergi

Hi,

put me in the bag too.

Need to pass the 75% in code coverage calling external webservices.

SuvraSuvra

Hello all,

 

Web Service Callouts are not supported by test methods. So, in web service callouts we can't get any code coverage. But we can increase the code coverage to a maximum level by modularizing the code.

Say, before making the callout we'll be preparing the request and after receiving output response will be formed.

So, we can have three separate methods for this purpose..

1. for Request forming

2. for Callout - this method will just contain the line which is actually making the call

3. for forming Response.

 

Now, in test method #1 will get covered, #2 and #3 will be left uncovered. Here we can form manual response and call method #3. This way only minimum no. of lines will be left untouched and coverage will be increased.

 

 Thanks and Regards,

 Suvra

This was selected as the best answer
Koen (BvD)Koen (BvD)

Needing to change an automatically generated class to get it by testing is absurd. Whoever stumbles on this post, please promote the ideas related to this topic on the ideas exchange (e.g. http://ideas.salesforce.com/article/show/10090248

 

Koen.