I have created a Batch Apex class and its associated Scheduler class. The classes work fine. I am now writing the test class for it but for some reason it just does not seem to cover the scheduler class. The test is passing because it completes but it actually does not cover the scheudler class. The apex code I wrote I wrote for the batch job is 100% covered, however. Do I need to add something extra in the test class to cover the scheduler class? I thought with the batch job it would take care of the scheduler class? Can someone help please?
The Batch Apex:
global class StatusSync implements Database.Batchable<sObject>, Database.AllowsCallouts {
public string queryStr;
global Database.QueryLocator start(Database.BatchableContext BC) {
return Database.getQueryLocator(queryStr);
}
global void execute(Database.BatchableContext BC, List<Ticket__c> records) { //this method is completely uncovered by test. Seems like it didnt enter it
AnotherClassServiceHandler.doStatusUpdate(records);
}
global void finish(Database.BatchableContext BC){
}
}
This is the scheduler class I wrote:
global class StatusSyncSheduler implements Schedulable {
global void execute(SchedulableContext sc) {
StatusSync batch = new StatusSync();
batch.queryStr = 'select Id, Name, Case_Number__c, Status__c, Case_Number__r.Request_Type__c from Ticket__c where Status__c != \'Closed\'';
ID batchprocessid = Database.executeBatch(batch,10);
}
} //This entire method is uncovered by test
Here is the test class I wrote:
@isTest
public class StatusSyncTest {
@isTest
static void testBatchStatus(){
Case testCase = new Case();
testCase.First_Name__c = 'test';
testCase.Last_Name__c = 'tester';
testCase.Request_Type__c = 'Provide My Info';
testCase.SuppliedEmail = 'test@test.com';
testCase.SuppliedPhone = '1115556200';
testCase.Street__c = '123 fake avenue';
testCase.City__c = 'Test City';
testCase.State__c = 'AZ';
testCase.Zip_Code__c = Decimal.ValueOf('90210');
testCase.Status = 'New';
insert testCase;
system.assertNotEquals(null, testCase.Id);
Ticket__c t = new Ticket__c();
t.Name = 'ABCDXYZ';
t.Case_Number__c = testCase.Id;
t.Status__c = 'New';
insert t;
StatusSync batch = new StatusSync();
Test.setMock(HttpCalloutMock.class, new ticketCalloutMock());
Test.startTest();
batch.queryStr = 'select Id, Name, Case_Number__c, Status__c, Case_Number__r.Request_Type__c from Ticket__c where Status__c != \'Closed\'';
Database.executeBatch(batch);
Test.stopTest();
}
}