+ Start a Discussion
Chris PulliamChris Pulliam 

APEX Test Class Error "Methods defined as TestMethod do not support Web service callouts" Opportunity

@isTest 

public class AccRelatedContTest
{    
      static testmethod void updateOpp() {
      
             Account testAccount = new Account();
        
        testAccount.Name='Test Account' ;        
        testAccount.OwnerID = '005d0000003Xjjh';
        testAccount.Website = 'hopethisworks.com';
        testAccount.recordtypeid = '012d0000000PBVJ';
        insert testAccount;
        
        Contact cont = new Contact();
        cont.FirstName='Test';
        cont.LastName='Test';
        cont.Accountid= testAccount.id;
        insert cont;
        
      Opportunity o = new Opportunity(
        Name='Test Opp',
        NextStep = 'Testing',
        Accountid= testAccount.id,
        StageName = 'Prospect',
        Probability=100,
        CloseDate = date.today(),
        RecordTypeid = '012d0000000PDkW');
        insert o;
        
        
    }
}
This is the test class code attempting to provide code coverage for an opportunity create and update trigger. When I run it without the opportunity part it passes fine, but when I include it gives a "Methods defined as TestMethod do not support Web service callouts" error, which is frustrating because I'm not making any Web service callouts (I think?!)

Any help is greatly appreciated. Thanks.
Best Answer chosen by Chris Pulliam
Hargobind_SinghHargobind_Singh
Chris, Opportunity might have a trigger which could be initiating a web-service call-out. You can either skip the callouts to be tested by using Test.isrunningTest or test only mock. Here is an article that might help:

http://salesforce.stackexchange.com/questions/3486/testing-httpcallout-with-httpcalloutmock-and-unittest-created-data

All Answers

Hargobind_SinghHargobind_Singh
Chris, Opportunity might have a trigger which could be initiating a web-service call-out. You can either skip the callouts to be tested by using Test.isrunningTest or test only mock. Here is an article that might help:

http://salesforce.stackexchange.com/questions/3486/testing-httpcallout-with-httpcalloutmock-and-unittest-created-data
This was selected as the best answer
Chris PulliamChris Pulliam
Thank you for the quick response!

I think you are right that it's triggering some callout from a related package. It won't let me uninstall the packages from the sandbox environment. 

Can you please advice how to write the test class to skip the callouts? I'm having trouble following the link you sent.
 
Hargobind_SinghHargobind_Singh
Hi, to skip the callout, you will need to add this condition to the place where the callout is being made, but you mentioned that it is a package and you might not be able to edit the code ? In that situation, you will need to write the test coverage for the callout using mock method as highlighted in the link I sent. Usually it requires to create a mock web service response, storing it in static resources and using that in your test methods.