Batch scheduler class testing

Template for batch & scheduler class test method:@isTest

private class Test_Nameofurclass {
    static testmethod void test_Nameofurclass (){
        DateTime currTime = DateTime.now();
        Integer min = currTime.minute();
        Integer hour = currTime.hour();
        String sch;
    if(min <= 58)
            sch = ‘0 ‘+ (min + 1) + ‘ ‘ + hour + ‘ * * ? ‘+ currTime.year();
        else
            sch = ‘0 0 ‘+ (hour + 1) + ‘ * * ? ‘+ currTime.year();
        Test.startTest();
    nameofschedularclass obj = new nameofschedularclass  ();
    String jobId = system.schedule(‘test’, sch, obj);
        CronTrigger ct = [SELECT id, CronExpression, TimesTriggered, NextFireTime FROM CronTrigger where id = :jobId];
        System.assertEquals(sch, ct.CronExpression);
        insert test records satisfying your query.
        database.executeBatch(new nameofurbatchclass());
        Test.stopTest();
    }
}

One Reply to “Batch scheduler class testing”

  1. I came to your page and noticed you could have a lot more traffic. I have found that the key to running a website is making sure the visitors you are getting are interested in your subject matter. There is a company that you can get traffic from and they let you try it for free. I managed to get over 300 targetted visitors to day to my website.

Comments are closed.