Notifications
Clear all
Sep 17, 2021 2:16 am
Getting the error - Method defined as testMethod do not support web service callouts
1 Reply
Sep 17, 2021 2:27 am
// Suppose if you have Schedulable apex, which does a callout, with the name SchedulableClass: global class SchedulableClass implements Schedulable { global void execute(SchedulableContext SC) { ConnectTo.callRemote(); } } // To schedule it, you run the following code as anonymous apex: SchedulableClass chpddImp = new SchedulableClass(); String schedule = '0 30 4 * * ?'; // to run every day at 4.30 am String jobID = system.schedule('Scheduled Job Name', schedule, chpddImp); // Following will be the test class for it: @isTest public class SchedulableClass_Test { @isTest static void testSchedulableClass() { String schedule = '0 30 4 * * ?'; Test.setMock(HttpCalloutMock.class, new MockHttpResponseImplementation()); Test.startTest(); String jobId = System.schedule('Scheduled Job Name', schedule, new SchedulableClass()); CronTrigger ct = [SELECT Id, CronExpression, TimesTriggered, NextFireTime FROM CronTrigger WHERE id = :jobId]; Test.stopTest(); System.assertEquals(schedule, ct.CronExpression); System.assertEquals(0, ct.TimesTriggered); } }