-2
 if(!test.isrunningtest()){
           try{
          String day = string.valueOf(system.now().adddays(2).day());
          String month = string.valueOf(system.now().adddays(2).month());
          String hour = string.valueOf(system.now().adddays(2).hour());
          String minute = string.valueOf(system.now().adddays(2).minute());
          String second = string.valueOf(system.now().adddays(2).second());
          String year = string.valueOf(system.now().adddays(2).year());
          String strJobName1 = 'Job-' + second + '_' + minute + '_' + hour + '_' + day + '_' + month + '_' + year;
          String strSchedule1 = '0 ' + minute + ' ' + hour + ' ' + day + ' ' + month + ' ?' + ' ' + year;
          System.debug('@@@@@@@@'+strSchedule1);
          id cronid = System.schedule(strJobName1,strSchedule1, new scheduledTest1(c.id));
          Schedule_Abort__c sb = new  Schedule_Abort__c();
          sb.name = cronid;
          sb.Casenumber__c =c.id;
          Scheduleaborts.add(sb);
            }

            catch(exception e){
            Logger.LogMessageWithException('Exception occurred while Sending Auto Acknowledgement', '', e);

            }
2
  • 1
    You will never be able to get test coverage for those lines of code... Unless of course you remove the if(!test.isrunningtest())
    – martin
    Commented Feb 24, 2016 at 6:45
  • why is test.isRunningTest() even in this prod class?
    – cropredy
    Commented Mar 1, 2016 at 6:03

1 Answer 1

0

test.isrunningtest() is specifically used to skip codes which will fail during test class execution or doesn't applies to test coverage.

I guess you don't want to schedule your job during test execution that's why you have added it inside test.isrunningtest() block.

Just to increase your test coverage, why dont you put ONLY the below code under test.isRunningTest() block?

id cronid = System.schedule(strJobName1,strSchedule1, new scheduledTest1(c.id));
Schedule_Abort__c sb = new  Schedule_Abort__c();
sb.name = cronid;
sb.Casenumber__c =c.id;
Scheduleaborts.add(sb);

Rest of your code can run safely during the test execution.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .