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
Eddie VazquezEddie Vazquez 

Error: Methods defined as TestMethod do not support Web service callouts Stack Trace: null

I'm a new admin for my org, when I try to run the test classes one of them fails and the error I receive is "Methods defined as TestMethod do not support Web service callouts Stack Trace: null". How do I resolve this? Here's my test class:

@isTest
public class TaskRelatedRecordStatus_Test {

    static Task tTask1;
    static Task tTask2;
    static Task tTask3;
    static Account tAccount1;
    static Account tAccount2;
    static Opportunity tOppty1;
    static Lead tLead1;

    static void createTestData(){
        tAccount1 = new Account(Name = 'Testco', Account_Status__c = '01 - Cold');
        tAccount2 = new Account(Name = 'Other Testco', Account_Status__c = '00 - Raw');
        INSERT tAccount1;
        INSERT tAccount2;

        tOppty1 = new Opportunity(Name = 'Widgets', StageName = '01 - Identifying an Opportunity', CloseDate = date.valueOf('2018-09-09'), AccountID = [SELECT Id FROM Account WHERE Name = 'Other Testco'].Id);
        tLead1 = new Lead(Company = 'ABCCo', Status='01 - New', LastName='Dodd');

        INSERT tOppty1;
        INSERT tLead1;
       
        tTask1 = new Task(whatID = [SELECT Id FROM Account WHERE Name = 'Testco'].Id);
        tTask2 = new Task(whatID = [SELECT Id FROM Opportunity WHERE Name = 'Widgets'].Id);
        tTask3 = new Task(whoID = [SELECT Id FROM Lead WHERE Company = 'ABCco'].Id);
        
        INSERT tTask1;
        INSERT tTask2;
        INSERT tTask3;

    }

    testMethod
    static void triggerInAction(){
        test.startTest();
            
        createTestData();

        tTask1 = [SELECT Account_Status__c FROM Task WHERE Id = :tTask1.Id];
        tTask2 = [SELECT Opp_Status__c FROM Task WHERE Id = :tTask2.Id];
        tTask3 = [SELECT Lead_Status__c FROM Task WHERE Id = :tTask3.Id];

        test.stopTest();

        System.assertEquals(tTask1.Account_Status__c, '01 - Cold');
        System.assertEquals(tTask2.Opp_Status__c, '01 - Identifying an Opportunity');
        System.assertEquals(tTask3.Lead_Status__c, '01 - New');
    }
}
Danish HodaDanish Hoda
Hi Eddie, You'd need a developer to resolve it either s/he create a mockup class for callouts from test class or use below condition wherever a callout is being made - 
if(!test.isRunningTest()) {
        ...
}
Eddie VazquezEddie Vazquez
Hi Danish! Thank you for your response, unfortunately, we don't have a dev in-house. Any documentation that I could follow along and do myself?
Danish HodaDanish Hoda
Hi Eddie, you could refer - https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_restful_http_testing_httpcalloutmock.htm