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%?

  • 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 at 18:03
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
}
| improve this answer | |
  • that helped! thanks a lot Keith C. – AndersenAnd Jan 5 at 18:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.