You need to sign in to do that
Don't have an account?
Ramanjot Sidhu
Test Class (Failing)
Assertion failed: same value :null
Hi,
I am trying to depoly from production to sandbox but one of my test classes are failing in production. I do not know what to do, I have researched everywhere and cannot find a solution. We have an eventbrite integration in Salesforce, and maybe I would have to contact them. If you could help out, I would appreciate it.
Error Details:
Error Message System.AssertException: Assertion Failed: Same value: null
Stack Trace Class.EventBriteRegistrantScheduleTest.EventBriteRegistrantScheduleTest: line 29, column 1
EventBriteClass:
global class EventBriteRegistrantSchedule implements Schedulable { // cron expression // Seconds Minutes Hours Day_of_month Month Day_of_week optional_year public static String CRON_EXP = '0 45 * * * ?'; public static String jobName = 'Scheduled Batch EventBrite Registrant Account/Contact Matching'; global void execute(SchedulableContext SC) { String q = ''; q = EventBriteRegistrantBatch.batchQuery; EventBriteRegistrantBatch brm = new EventBriteRegistrantBatch(q); ID batchprocessid = Database.executeBatch(brm, brm.scopeLimit); } public static CronTrigger scheduleJob() { CronTrigger ct = null; try { // Schedule the test job String jobId = System.schedule(jobName, EventBriteRegistrantSchedule.CRON_EXP, new EventBriteRegistrantSchedule()); // Get the information from the CronTrigger API object ct = [SELECT id, CronExpression, TimesTriggered, NextFireTime FROM CronTrigger WHERE id = :jobId]; } catch (Exception e) { System.Debug(LoggingLevel.ERROR, 'Job already scheduled'); } return ct; } public static void unscheduleJob() { // Get the information from the CronTrigger API object List<CronTrigger> cts = [SELECT Id, CronExpression, TimesTriggered, NextFireTime FROM CronTrigger WHERE CronExpression = :CRON_EXP]; if (cts != null) { for (CronTrigger ct : cts) { System.abortJob(ct.Id); } } } }
Test Class (Failing)
@isTest public class EventBriteRegistrantScheduleTest { @isTest public static void EventBriteRegistrantScheduleTest() { CronTrigger ct; DateTime dateToday = DateTime.now(); // calculate next run time DateTime nextRun = dateToday; if (dateToday.minute() < 45) { nextRun = DateTime.newInstance(nextRun.year(), nextRun.month(), nextRun.day(), nextRun.hour(), 45, 0); } else { nextRun = nextRun.addHours(1); nextRun = DateTime.newInstance(nextRun.year(), nextRun.month(), nextRun.day(), nextRun.hour(), 45, 0); } // specify job name String jobName = EventBriteRegistrantSchedule.jobName; Test.startTest(); // Schedule job ct = EventBriteRegistrantSchedule.scheduleJob(); // Verify successfully created system.assertNotEquals(null, ct); // Verify the expressions are the same System.assertEquals(EventBriteRegistrantSchedule.CRON_EXP, ct.CronExpression); // Verify the job has not run System.assertEquals(0, ct.TimesTriggered); // Verify the next time the job will run System.assertEquals(nextRun, ct.NextFireTime); // Try scheduling job again ct = EventBriteRegistrantSchedule.scheduleJob(); // Verify job failed system.assertEquals(null, ct); Test.stopTest(); EventBriteRegistrantSchedule.unscheduleJob(); } }