function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
chaithaly gowdachaithaly gowda 

Batch class is not executing in test class

Hi 

I have this code in my test class
 User u = [select Id from User where id =: UserInfo.getUserId() limit 1];
            system.runAs(u){
            Test.startTest(); 
            ReminderController m = new ReminderController('30 Days Reminder');
            String sch = '0 15 0 * * ?';
            String jobID = system.schedule('Actions Job',sch,m);
            Test.stopTest();
                
             list<actions__c> sc=[select id from actions__c];
             system.assertEquals(1, sc.size());  
               
        }
         
    }
with this code... start ,execute method of batch class are not executing..
User u = [select Id from User where id =: UserInfo.getUserId() limit 1];
            system.runAs(u){
            Test.startTest(); 
            ReminderController m = new ReminderController('30 Days Reminder');
            String sch = '0 15 0 * * ?';
            String jobID = system.schedule('Actions Job',sch,m);
            Test.stopTest();
               
        }
         
    }
and with this code... the batch class is running properly... I am not sure whats wrong.

Help needed to resolve this
,Thanks
AnudeepAnudeep (Salesforce Developers) 
I don't see any issue with the code. Did you try running the test with a regular user by removing system.runAs(u)?
chaithaly gowdachaithaly gowda
Yes Anudeep.. I tried running without runas(u) as well,issue still persists
AnudeepAnudeep (Salesforce Developers) 
The only difference I find between both the code snippets is the following two lines. Have you tried checking by removing the assert statement?
 
list<actions__c> sc=[select id from actions__c];
             system.assertEquals(1, sc.size());

 
chaithaly gowdachaithaly gowda
code works fine without
 list<actions__c> sc=[select id from actions__c]; system.assertEquals(1, sc.size());
I wanted to do assert equals, but with these two statements, the batch class isnot getting called at all.