You need to sign in to do that
Don't have an account?
prady-cm
Apex batch class start method not running
I have apex batch class
global class apexBatch implements Database.Batchable<sObject>{ global final string query; List<user> lstUser= new List<user>(); Set<id> setUserID= new Set<id>(); //constructor global apexBatch () { if (system.Test.isRunningTest()) { this.query='SELECT id FROM user limit 100'; } else { this.query='SELECT id FROM user ; } } global Database.QueryLocator start(Database.BatchableContext BC) { return Database.getQueryLocator(query); } global void execute(Database.BatchableContext BC, List<sObject> scope) { // do some processing } global void finish(Database.BatchableContext BC) { }
I am calling this class from test class using this code
Test.startTest(); apexBatch ba = new apexBatch(); Database.executeBatch(ba); Test.stopTest();
When i check the code coverage i can only see that the constructor is covered, the start and execute methods are not covered at all.
Any idea what could cause this
Thanks
Hi,
When I tried it give 90% coverage with the same code
Following test method I have used.
@isTest
private class TestClass
{
public static testmethod void test()
{
Test.startTest();
apexBatch ba = new apexBatch();
Database.executeBatch(ba);
Test.stopTest();
}
}
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
This is really strange...
i am doing exactly the same..
Did it cover the start method or the execute method?
My guess is that the 10 percent not covered are the start and executemethods
I need apex batch class, for fetched query results put into .xls file and this .xls file needs to transfer via vf email templates.
I am facing the same issue now. Still no any idea about this.