You need to sign in to do that
Don't have an account?
DIVYANSHU BHUSHAN
Test Class for Schedulable batch
Hello friends, I have a schedulable class.
and it's test class is here
But the test class is covering only "IF" condition of schedulable class.Please help. Thanks in anticipation :)
global class SchedulableTNOFTPJob implements Schedulable { global void execute(SchedulableContext sc) { if ([SELECT count() FROM AsyncApexJob WHERE (JobType='BatchApex' OR JobType='ScheduledApex') AND (Status = 'Processing' OR Status = 'Preparing')] < 5){ try { //for(Integer i=0; i < 50; i++) { Datetime sysTime = System.now(); ProcessTNOFiles batch = new ProcessTNOFiles(); Id cronId = System.scheduleBatch(batch, 'schedFiles' + sysTime.getTime(), 1); //} } catch (System.AsyncException ae) { } } else { System.debug(LoggingLevel.WARN,'ProcessTNOFiles Finished'); //Build the system time of now + 20 seconds to schedule the batch apex. Datetime sysTime = System.now(); Integer rand = Integer.valueOf(Math.Random() * 10); sysTime = sysTime.addSeconds(20+rand); String chron_exp = '' + sysTime.second() + ' ' + sysTime.minute() + ' ' + sysTime.hour() + ' ' + sysTime.day() + ' ' + sysTime.month() + ' ? ' + sysTime.year(); system.debug(chron_exp); SchedulableTNOFTPJob ftpFiles = new SchedulableTNOFTPJob(); //Schedule the next job, and give it the system time so name is unique Id cronId = System.schedule('ftpFiles' + sysTime.getTime(),chron_exp,ftpFiles); System.abortJob(sc.getTriggerId()); System.debug('*******ProcessTNOFiles FAIL CRON ID: '+cronId+', but MAIN ID: '+sc.getTriggerId()); } } }
and it's test class is here
@isTest public class TestSchedulableTNOFTPJob { static testMethod void myUnitTest() { test.startTest(); AsyncApexJob aa = new AsyncApexJob(); SchedulableTNOFTPJob nightlyUpdate = new SchedulableTNOFTPJob(); String schedule = '0 0 23 * * ?'; system.schedule('Nightly Update', schedule, nightlyUpdate); test.stopTest(); } }
But the test class is covering only "IF" condition of schedulable class.Please help. Thanks in anticipation :)