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
chaithaly gowdachaithaly gowda 

Test class not covering start method of the batch class

Hi 

I have a batch class 'TerritoryDetails' which has been scheduled in 'ScheduleTerritoryDetails'.

I have a test class 'TestScheduleTerritoryDetails'
public with sharing class TestLFDTerritoryScheduler {

    @TestSetup
    static void makeData(){
//Testdata created
}

static testmethod void test(){
    Test.startTest();
    ScheduleTerritoryDetails m = new ScheduleTerritoryDetails();
          String hour = '0';
        string minute = '30';
        string sec = '0';
  String sch =  sec+ ' '+ minute+' '+ hour +' '+'* * ?'; 
String jobName = 'Update ';
id jobId = system.schedule(jobName, sch, m);
}


and in scheduler class , the batch class has been called.
TerritoryDetails b = new TerritoryDetails();
database.executeBatch(b, 3); 

but when I execute the test class, it is covering 100% of scheduler class,but  not covering the batch class.
Can someone please help in covering this batch class.
 
Vishwajeet kumarVishwajeet kumar
Hello,
Looks like batch job is not running. Try to put Test.stopTest(); after scheduled job statement.

Thanks