Stack Exchange
test class is not running execute method
thsi is batch class:
global class Batch_ValueEdge_NotifyAID implements Database.Batchable<SObject>, Database.Stateful {
    public Integer currentYear = System.Today().year();
    global Database.QueryLocator start(Database.BatchableContext BC){
        string query = 'select Id,Distributor_AID__c,Distributor_AID__r.Email,Distributor_AID__r.Name,Group_code__c,Customer_Code__c,Year__c  from Value_Edge__c Where Group_code__c != null and Year__c =: currentYear';
        return Database.getQueryLocator(query);
    }
    global void execute(Database.BatchableContext BC, List<Value_Edge__c> scope){
        Date dtToday = system.today();
        integer nMonth = dtToday.month();
        integer nBatchRunDay = dtToday.day();
        ValueEdge__mdt objNotifyDates = [Select Id, Notification_Day__c,Notification_Remainder_Day__c from ValueEdge__mdt];
        
        Boolean STartQuarterInitial = false;
        if(nBatchRunDay == objNotifyDates.Notification_Day__c && (nMonth == 1 || nMonth == 4 || nMonth == 7 || nMonth == 10)){
            STartQuarterInitial = true;
        }
        
        Boolean EndQuarterReminder = false;
        if(nBatchRunDay == objNotifyDates.Notification_Remainder_Day__c && (nMonth == 1 || nMonth == 4 || nMonth == 7 || nMonth == 10)){
            EndQuarterReminder = true;
        }
        if(scope != null && scope.size() > 0 ){
            List <Messaging.SingleEmailMessage> mailList = new List <Messaging.SingleEmailMessage>();
            List <string> lstEmail = new List <string>();
            system.debug('scope' + scope);
            
            if(STartQuarterInitial == true || EndQuarterReminder == true){
                for(Value_Edge__c objVE : scope){
                    if(objVE.Distributor_AID__c != null){
                        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();                        
                        if(objVE.Distributor_AID__r.Email != null){
                            lstEmail.add(objVE.Distributor_AID__r.Email); 
                        }
                        system.debug('lstEmail'+ lstEmail.size());
                        if(lstEmail != null && lstEmail.size() > 0){
                            mail.setToAddresses(lstEmail);
                            if(STartQuarterInitial == true){
                                mail.setSubject('Value Edge window open for submission');
                                String messageBody = 'Hi ' +  objVE.Distributor_AID__r.Name + ',' + '<br/>';
                                messageBody += 'The Value Edge window is open for the quarter till 15th of the month.'+
                                    ' Request you to fill the details and Save/Submit your Value Edge request' + '<br/>';
                                messageBody += 'Below are the details: ' + '<br/>' ;
                                messageBody += 'Group Code: : ' + objVE.Group_Code__c + '<br/>';
                                messageBody += 'Customer Code : ' + objVE.Customer_Code__c + '<br/>';
                                messageBody += 'Year : ' + integer.valueOf(objVE.Year__c) + '<br/>' ;
                                messageBody += 'Kindly take approriate action.' + '<br/>';
                                mail.setHtmlBody(messageBody);
                                mailList.add(mail);
                            }else if(EndQuarterReminder == true){
                                mail.setSubject('Gental Reminder for Value Edge');
                                String messageBody = 'Hi ' +  objVE.Distributor_AID__r.Name + ',' + '<br/>';
                                messageBody += 'The Value Edge window is open for the quarter till 15th of the month.'+
                                    ' Request you to fill the details and Save/Submit your Value Edge request' + '<br/>';
                                messageBody += 'Below are the details: ' + '<br/>' ;
                                messageBody += 'Group Code: : ' + objVE.Group_Code__c + '<br/>';
                                messageBody += 'Customer Code : ' + objVE.Customer_Code__c + '<br/>';
                                messageBody += 'Year : ' + integer.valueOf(objVE.Year__c) + '<br/>' ;
                                messageBody += 'If already submitted please ignore the same!' + '<br/>';
                                mail.setHtmlBody(messageBody);
                                mailList.add(mail);
                            } 
                        }
                    }
                    lstEmail.clear();
                }
                Messaging.sendEmail(mailList);  
            } 
        }
    }
    global void finish(Database.BatchableContext BC){
        
    }

and this is my test class:
@IsTest(SeeAllData=false)
public class Test_Batch_ValueEdge {
    static testMethod void Testdatavalueedge() 
    {
    
        List<Account> lstAccount = new list<Account>();
        Account acc = new Account();
        acc.Name='Orienfdft Enterprise (G) Pvt. Ltd';
        acc.Group_code__c = 'GRP123';
        acc.ERPCode__c =5458;
        acc.Name ='TestdfdDemo';
        acc.Customer_ID__c= '234';
        acc.GST_Number__c='abcdefgh123456GG';
        acc.Credit_limit__c= 3400;
        acc.TAN_number__c='12356';
        acc.ERPCode__c = 3000;
        acc.TM_code__c= 7800;
        acc.Email_Id__c = 'Test@gmail.com';
        acc.PAN_number__c='9098745466';
        acc.TM_Name__c='Demo';
        acc.Distributor_Owner__c = userInfo.getUserId();
        lstAccount.add(acc);
        insert lstAccount;
        
        Integer currentYear1 = System.Today().year();
        List<Value_Edge__c> lstvalue = new List<Value_Edge__c>();
        Value_Edge__c objVE = new Value_Edge__c();
        objVE.Distributor__c = acc.Id;
        objVE.Group_Code__c = acc.Group_code__c;
        objVE.Customer_Code__c = string.valueOf(acc.ERPCode__c);
        objVE.Year__c = 2021;
        objVE.Distributor_AID__c = userInfo.getUserId();
        lstvalue.add(objVE);
        insert  lstvalue;
        
        
        
        string currentYear = string.valueOf(System.today().year());
        List<Program_criteria__c> lstPC =  new List<Program_criteria__c>();        
        Program_criteria__c objc = new Program_criteria__c();
        objc.calculation_Basis__c = 'Percentage';
        objc.Core_Area__c = 'Reach';
        objc.Group_Outlet__c = 'Group';
        objc.Is_prorated__c = true;
        objc.Value_compared__c = 10;
        objc.Key_criteria__c = 'Additional 10% Net new end customer on total secondary sales end customer base as on 31st Dec 2020.For >10%, a prorated multiplier will be applied';
        objc.Parameters__c = 'Net New Customer addition';
        objc.Is_Active__c = true;
        objc.Year__c = string.valueOf(system.today().year());
        objc.Year__c = currentYear;
        objc.Is_Group_Total_Row__c = true;
        lstPC.add(objc);
        insert lstPC;
        
        
        List<VE_Calculation__c> lstve = new List<VE_Calculation__c>();
        VE_Calculation__c VEcal = new VE_Calculation__c();
        VEcal.calculation_Basis__c = '';
        VEcal.Value_Edge__c = objVE.Id;
        VEcal.Group_Code__c = objVE.Group_Code__c;
        VEcal.Year__c = objc.Year__c;
        VEcal.Value_Edge__c =objVE.Id;
        VEcal.Unique_Id__c = objc.Id + objVE.Group_Code__c + system.today();
        VEcal.Key_criteria__c = objc.Key_criteria__c;
        VEcal.Parameter__c = objc.Parameters__c;
        VEcal.Core_Area__c = objc.Core_Area__c;
        VEcal.Status__c = 'Verified';
        lstve.add(VEcal);
        upsert lstve ;
        
        Test.startTest();
        Batch_ValueEdge batchvalueedge = new Batch_ValueEdge();
        Database.executeBatch(batchvalueedge);
        batchvalueedge.execute(null, lstAccount);
        
        Batch_ValueEdge_NotifyAID cb = New Batch_ValueEdge_NotifyAID();

        Database.QueryLocator ql = cb.start(null);
        cb.execute(null,lstvalue);  
        cb.Finish(null);
        
        Batch_ValueEdge_NotifyAID valueedgebatch = new Batch_ValueEdge_NotifyAID();
      //  Batch_ValueEdge_NotifyAID.fakeMethod();
        Database.executeBatch(valueedgebatch);
        Id batchJobId = Database.executeBatch(new Batch_ValueEdge_NotifyAID(), 200);
        //Batch_ValueEdge_NotifyAID.Fakemethod();
        Test.stopTest();
        
    }
}


Welcome to SSE ! While creating Value_Edge__c record you are giving Year__c as 2021. But your start query has current year filter. Can you check and update based on it

tried with 2022, but even if its covering select query, its not covering the for loop.

Is the test class covering Execute method till for loop?

yes let it be, solved

Hi Kapil, If the issue is resolved then can you put how it got resolved so it helps other developers if they face the same issues

it all depends on the Custom metadata settings
