Batch scheduler class testing

Template for batch & scheduler class test method:@isTest

private class Test_Nameofurclass {
    static testmethod void test_Nameofurclass (){
        DateTime currTime =;
        Integer min = currTime.minute();
        Integer hour = currTime.hour();
        String sch;
    if(min <= 58)
            sch = ‘0 ‘+ (min + 1) + ‘ ‘ + hour + ‘ * * ? ‘+ currTime.year();
            sch = ‘0 0 ‘+ (hour + 1) + ‘ * * ? ‘+ currTime.year();
    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());

SFDC API 24.0 test failure issue

Yesterday I was experiencing a weird issue. My SFDC API Test Failed.For a new requirement we did development in our DEV environment…We wrote new test methods and we thought the work is done :)…
However, there were Null Pointer Exceptionswhen we ran the test methods.
And it was pointing to the custom settings….we doubled checked and confirmed that the custom setting had the default values. Also, it was accessible to anyone (public).After some time I realized that the test method API version was 24.0.. I changed it to 23.0 and there were no errors 🙂

Edit – SFDC has introduced test classes not to access data directly with API 24. Even though it is a good move , I would like to access certain info by default like custom settings, and Pricebook. But there is always an option to use @istest(seealldata=true) to access live data.