0

console code coverage

Here is my schedule class :

global class Scheduler_class implements Schedulable{
public static String CRON_EXP = '0 00 00 * * ?'; //Every Day at Midnight
    global static String scheduleMe() {
        Scheduler_class SC = new Scheduler_class(); 
        return System.schedule('b1', CRON_EXP, SC);
    }
    global void execute(SchedulableContext sc) {
         batchprocessopportunity b1 = new  batchprocessopportunity();
        ID batchprocessid = Database.executeBatch(b1,50);           
    }
}

and here is my test class:

@isTest
private class TestScheduler_class {
    static testMethod void myTestMethod() {        
   Test.startTest();
      String jobId = System.schedule('testBasicScheduledApex',Scheduler_class.CRON_EXP, new Scheduler_class());
   // Get the information from the CronTrigger API object 
      CronTrigger ct = [SELECT Id, CronExpression, TimesTriggered,NextFireTime FROM CronTrigger WHERE id = :jobId];
   // Verify the expressions are the same   
      System.assertEquals(Scheduler_class.CRON_EXP, ct.CronExpression);
   // Verify the job has not run     
      System.assertEquals(0, ct.TimesTriggered);
   // Verify the next time the job will run   
     System.assertEquals('2014-05-13 00:00:00', String.valueOf(ct.NextFireTime));
       Test.stopTest();

   }
    }

Help me to get the code coverage for the following lines red in color.

3

Try adding this line to your test:

Scheduler_class.scheduleMe();

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.