You need to sign in to do that
Don't have an account?

Need help with batch apex test class code coverage
Hello,
I'm trying to navigate my way through this apex test case and I've not been successful. Could anyone assist with bringing coverage up from 46%?
Thank you.
Test Class:
Batch Class:
I'm trying to navigate my way through this apex test case and I've not been successful. Could anyone assist with bringing coverage up from 46%?
Thank you.
Test Class:
@isTest private class CHIEventsMonitorTest { @testSetup static void setup() { List<Event__c> events = new List<Event__c>(); // insert 10 events for (Integer i=0;i<10;i++) { events.add(new Event__c(name='Event '+i, CreatedDate = DateTime.now(), LastModifiedDate = DateTime.now(), Event_End_Date__c = Date.today(), CHI_Publish_To_Website__c = false, CHI_Status__c = 'Planned', Send_to_Consultants_for_Assignment_c__c = false, EvaluationPilot__c = false, Send_Attendance_Email__c = false, Completed__c = false)); } insert events; } static testmethod void test() { Test.startTest(); CHIEventsMonitor uca = new CHIEventsMonitor(); Id batchId = Database.executeBatch(uca); Test.stopTest(); } }Note - Most of this was accomplished with the help of Google (obviously, or I probably wouldn't be here)
Batch Class:
global class CHIEventsMonitor implements Database.Batchable<sObject>{ List<Event__c> eventToUpdate = new List<Event__c>(); Date dt = date.today(); String query = 'Select Id, CHI_Status__c, Completed__c, Send_Attendance_Email__c From Event__c WHERE IsFinished__c = FALSE AND Event_End_Date__c =: dt'; global Database.QueryLocator start(Database.BatchableContext BC){ return Database.getQueryLocator(query); } global void execute(Database.BatchableContext BC, List<Event__c> event){ for(Event__c c : event){ if(c.Completed__c==FALSE){ c.Send_Attendance_Email__c = TRUE; c.Completed__c = TRUE; eventToUpdate .add(c ); } } update eventToUpdate ; } global void finish(Database.BatchableContext BC){ } }
You batch apex query is looks not correct and give me whihc lines are not covering
Change your batch apex class as below
You batch class is not correct i gueess
It appears my issue is the test class is not covering the updates to the records.
Is there any formulas
Thank you for your help so far.
between the batch execution and test.stoptest
Thank you for your help.