You need to sign in to do that
Don't have an account?
srinivas pulipati
Hi I am writing BatchApex class code is execute successfully but i wrote test class for batch apex it is also execute successfully but code coverage is show 57% plz check once
Batch Apex Class:
global class BatchClass implements database.Batchable<Sobject>{
global database.QueryLocator start(Database.BatchableContext bc){
String Query='select id from account';
return Database.getQueryLocator(Query);
}
global void execute(Database.BatchableContext bc , List<Sobject> scope){
List<Account> acc=new List<Account>(); ///These 3 line are not execute when i run the test code
for(account a : acc){
system.debug('a');
//acc.add(a);
}
// update acc;e
}
global void finish(Database.BatchableContext bc){
System.debug('finished');
}
}
Batch Test Class:
@istest
private class TestBatchClass{
static testmethod void testbatchclass(){
BatchClass bc=new BatchClass();
string Query='select id from account limit 200';
test.startTest();
Database.executeBatch(bc,200);
List<Account> acc=new List<Account>();
//BatchableContext bc;
//bc.execute(bc,acc);
test.stopTest();
}
}
When i run the test class code coverage is Show 57%
global class BatchClass implements database.Batchable<Sobject>{
global database.QueryLocator start(Database.BatchableContext bc){
String Query='select id from account';
return Database.getQueryLocator(Query);
}
global void execute(Database.BatchableContext bc , List<Sobject> scope){
List<Account> acc=new List<Account>(); ///These 3 line are not execute when i run the test code
for(account a : acc){
system.debug('a');
//acc.add(a);
}
// update acc;e
}
global void finish(Database.BatchableContext bc){
System.debug('finished');
}
}
Batch Test Class:
@istest
private class TestBatchClass{
static testmethod void testbatchclass(){
BatchClass bc=new BatchClass();
string Query='select id from account limit 200';
test.startTest();
Database.executeBatch(bc,200);
List<Account> acc=new List<Account>();
//BatchableContext bc;
//bc.execute(bc,acc);
test.stopTest();
}
}
When i run the test class code coverage is Show 57%
Try with below code .
Let m eknow if it helps !!
Thanks
Manoj
Your probelem is resolved or still you have issue .If resolved please cllose the thred by selecting answer to help others in forum those who are facing sam etype of issue .
Thanks
Mnaoj