Skip to main content

I'm getting this error "Methods defined as TestMethod do not support Web service callouts" in Apex Scheduler Test class.  My code as below...

 

global class DailyFetchMSDynamicCRMLeads implements Schedulable {

global void execute(SchedulableContext ctx) {

MSDynamicCRMUtilityService msDynCRM = new MSDynamicCRMUtilityService();

MSDynamicCRMUtilityService.GetLeadsFromMSDynamic();

}

}

 

@isTest

public class DailyFetchMSDynamicCRMLeadsTest {

@isTest

static void TestDailyFetchMSDynamicCRMLeads(){//testmethod

Test.startTest();

Lead lObj = new Lead();

lObj.FirstName = 'Test FirstName';

lObj.LastName = 'Test LastName';

lObj.Company = 'Test Company';

insert lObj;

// This test runs a scheduled job at midnight Sept. 3rd. 2022

String CRON_EXP = '0 0 0 3 9 ? 2022';

// Schedule the test job

String jobId = System.schedule('DailyFetchMSDynamicCRMLeads', CRON_EXP, new DailyFetchMSDynamicCRMLeads());

// Get the information from the CronTrigger API object

CronTrigger ct = [SELECT Id, CronExpression, TimesTriggered, NextFireTime FROM CronTrigger WHERE id = :jobId];

// Verify the expressions are the same System.assertEquals(CRON_EXP, ct.CronExpression);

// Verify the job has not run

System.assertEquals(0, ct.TimesTriggered);

// Verify the next time the job will run

System.assertEquals('2022-09-03 00:00:00', String.valueOf(ct.NextFireTime));

Test.stopTest();

}

}

답변 1개
0/9000