You need to sign in to do that
Don't have an account?
Apex Specialist Superbadge Challenge #6 - Can't get successful run
I'm stuck. Worked through most of my issues but now every time I run the test on this test class I get a "Methods defined as TestMethod do not support Web service callouts" error. Can someone help identify what I have incorrect in my test class? Is there something I have to do to force it to use the Mock instead that I just don't see?
Here's that I have in the test class:
@isTest
public class WarehouseSyncTest {
@isTest static void testScheduledJob() {
String CRON_EXP = '0 0 0 15 3 ? 2022';
Test.startTest();
String jobid = System.schedule('EquipTest', CRON_EXP, new WarehouseSyncSchedule());
Test.stopTest();
CronTrigger ct = [SELECT State FROM CronTrigger WHERE ID = :jobId];
System.assertEquals('WAITING', String.valueOf(ct.State));
}
}
Have also tried it with private instead of public on the class - and I get the same error.
Here's that I have in the test class:
@isTest
public class WarehouseSyncTest {
@isTest static void testScheduledJob() {
String CRON_EXP = '0 0 0 15 3 ? 2022';
Test.startTest();
String jobid = System.schedule('EquipTest', CRON_EXP, new WarehouseSyncSchedule());
Test.stopTest();
CronTrigger ct = [SELECT State FROM CronTrigger WHERE ID = :jobId];
System.assertEquals('WAITING', String.valueOf(ct.State));
}
}
Have also tried it with private instead of public on the class - and I get the same error.
But what I did need was the Test.setMock(HttpCalloutMock.class, new WarehouseCalloutServiceMock()); line in my class above (already had the rest)
All Answers
Hey, You can check my Code below as Referrence.
Methods defined as TestMethod do not support Web service callouts , So we Create a Mock Class (WarehouseCalloutServiceMock in this case) which serves as a fake Webservice to receive our callout from the Test class.
WarehouseCalloutServiceMock :
Please mark this Solution as Best Solution if it solves your Question.
Best,
Nithesh.
But what I did need was the Test.setMock(HttpCalloutMock.class, new WarehouseCalloutServiceMock()); line in my class above (already had the rest)
However, did you see any record being fetched from the MockService?
I am not able to see that record being fetched and am unable to understand what I have done wrong here.
The SQL count returns 0
Also, the CronTrigger Status for the job is returned as Waiting post the StopTest();
Am I doing something wrong?
private class WarehouseSyncScheduleTest {
public static String CRON_EXP = '0 0 0 15 3 ? 2022';
static testmethod void testjob(){
MaintenanceRequestTest.CreateData( 5,2,2,'Repair');
Test.startTest();
Test.setMock(HttpCalloutMock.class, new WarehouseCalloutServiceMock());
String joBID= System.schedule('TestScheduleJob', CRON_EXP, new WarehouseSyncSchedule());
// List<Case> caselist = [Select count(id) from case where case]
Test.stopTest();
}
}
the code works.. you can find more solutions at salesforcehandle.com
how to solve this error. Kindly help
in test method to gain 100% coverage.