1

I have a scheduler class that looks like this

global class PBEntryUpdateScheduler implements Schedulable {

    public static String executionTime = '0 0 3 * * ?';


    global static String scheduleMe() {
        PBEntryUpdateScheduler ScheduleClass = new PBEntryUpdateScheduler(); 
        return System.schedule('Batch execution', executionTime, ScheduleClass);
    }

    global void execute(SchedulableContext ctx) {

        PBEntryUpdateBatch b1 = new PBEntryUpdateBatch();
        Database.executebatch(b1);

    }
}

But so far my test coverage is only 57%. My test class looks like this:

@isTest
private class PBEntryUpdateSchedulerTest {


    @isTest static void testScheduleMe() {

        Test.startTest();

        PBEntryUpdateScheduler bpEntry = new PBEntryUpdateScheduler();
        String newExeTime = '0 0 3 * * ?';
        String jobId = System.schedule('Scheduler Test', newExeTime, bpEntry);

        Test.stopTest();


    }


}

Can anyone help in getting the code coverage to 75%?

1
  • note using Keith's answer, you should also assert that an asyncApexJob was created as otherwise you're not proving that a schedulable was started
    – cropredy
    Jan 6, 2020 at 18:03

1 Answer 1

3

Launching via the static method - presumably added to make that simple - should help:

@isTest static void testScheduleMe() {

    // Set up any data needed for the code to work

    Test.startTest();
    PBEntryUpdateScheduler.scheduleMe();
    Test.stopTest();

    // Assert that the results you expect are present
}
1
  • that helped! thanks a lot Keith C. Jan 5, 2020 at 18:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .