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
Chidanand MChidanand M 

FATAL_ERROR|System.TypeException: Methods defined as TestMethod do not support Web service callouts, test skipped

Hi friends,

I have written a test class for my trigger in account object.
But whever i run the test class, i am getting the fowwing error


FATAL_ERROR|System.TypeException: Methods defined as TestMethod do not support Web service callouts, test skipped.

I have some of the managed packages inside the Account object.
The same test class when i run before refreshing my sandbox it was working fine. But the problem started after refreshing the sandbox. But other object testclasses r running correctly.

Here is my complete error message

00:25:27.648 (3648848170)|CODE_UNIT_FINISHED|territoryownerTest.checkStateCountry 00:25:27.650 (3650894509)|EXECUTION_FINISHED 00:25:27.654 (3654729375)|ENTERING_MANAGED_PKG|ClientSuccess 00:25:27.655 (3655562162)|FATAL_ERROR|System.TypeException: Methods defined as TestMethod do not support Web service callouts, test skipped (ClientSuccess) 00:25:27.655 (3655576096)|FATAL_ERROR|System.TypeException: Methods defined as TestMethod do not support Web service callouts, test skipped (ClientSuccess)

Can anyone tell me how to resolve this issue.




 
KaranrajKaranraj
Hi Chidu - Your test class execution is intiating the webservice callout code. 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 WebServiceMockinterface and the Test.setMock method that you can use to receive fake responses in a test method.

You have to make a mock callout in your test class to avoid that problem
Test.setMock(WebServiceMock.class, new WebServiceMockImpl());

Check this link to know more about Testing Webservice Callout (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_callouts_wsdl2apex_testing.htm) in apex 
Chidanand MChidanand M
@karanraj. Thank you.

Could u plz tell me where do i need to add it in my test class.
Here is my test class.
@isTest

public class territoryowner {




   static testMethod void checkStateCountry() {

    
        Territory_Owner__c cs= new Territory_Owner__c(Country__c='USA',State__c='OR',Account_Owner__c='Chris Burton'); 
        insert cs;
   
        Account act=new Account(Name='testNew',BillingCountry='USA',BillingState='OR');
        insert act;
        
        
   
   
   
   
   
}

}
TIA
 
Chidanand MChidanand M
@kaanraj
Even after adding setMock() method also, m getting the same error.
I just followed the link that u sent and created an interface and class.
But still the issue is not unsolved