+ Start a Discussion
udayarangareddy mekalaudayarangareddy mekala 

Trigger Test Class

HI
I got the error in the Trigger Test Class.The error is Selected job is not yet complete in Apex Test Execution.


Thanks&Regards
Ranga

 
Amit Chaudhary 8Amit Chaudhary 8
// Below code Abort all job
                    for (CronTrigger ct : [SELECT Id FROM CronTrigger]) {
                        System.abortJob(ct.Id);
                    }

Please try below code. I hope that will help you
@isTest
private class CustomerPortalRevokeSchedulableTest {

    static testMethod void myUnitTest() {

            Test.startTest();
					
					// Below code Abort all job
					for (CronTrigger ct : [SELECT Id FROM CronTrigger]) {
						System.abortJob(ct.Id);
					}	
				
					// Then try below code to schedule job
                    String CRON_EXP = '0 0 0 1 1 ? 2025';  
                    String jobId = System.schedule('testScheduledApex', CRON_EXP, new CustomerPortalRevokeSchedulable() );

                    CronTrigger ct = [select id, CronExpression, TimesTriggered, NextFireTime from CronTrigger where id = :jobId];

                    System.assertEquals(CRON_EXP, ct.CronExpression); 
                    System.assertEquals(0, ct.TimesTriggered);
                    System.assertEquals('2025-01-01 00:00:00', String.valueOf(ct.NextFireTime));

            Test.stopTest();
    }
}


Please let us know if this will help you