You need to sign in to do that
Don't have an account?
suji srinivasan
how to achieve100%test coverage for this batch class.
global class UpdateRating implements Database.Batchable<sObject>, Database.Stateful {
global Integer recordsProcessed = 0;
global Database.QueryLocator start(Database.BatchableContext bc) {
string query='select Rating,(select StageName from Opportunities where StageName=\''+String.escapeSingleQuotes('Inprogress,Delivered,closedwon')+ '\') From account where Rating <> \''+String.escapeSingleQuotes('client') + '\'';
return Database.getQueryLocator(query);
}
global Void execute(Database.BatchableContext bc, List<Account> Scope){
for(Account a :Scope){
a.Rating='client';
recordsProcessed = recordsProcessed + 1;
}
update Scope; }
global void finish(Database.BatchableContext bc){
System.debug(recordsProcessed + 'records processed. Shazam!');
}
}
test class
@isTest public class UpdateAccountRatingTest {
@testSetup static void setup() {
Account ac =new Account();
ac.Name = 'test';
ac.rating='prospect';
insert ac;
ac.Name = 'test';
ac.rating='client';
update ac; }
@isTest static void test() {
Test.startTest();
UpdateAccountRating uar = new UpdateAccountRating();
Id batchId = Database.executeBatch(uar);
Test.stopTest(); } }
Thanks in advance
global Integer recordsProcessed = 0;
global Database.QueryLocator start(Database.BatchableContext bc) {
string query='select Rating,(select StageName from Opportunities where StageName=\''+String.escapeSingleQuotes('Inprogress,Delivered,closedwon')+ '\') From account where Rating <> \''+String.escapeSingleQuotes('client') + '\'';
return Database.getQueryLocator(query);
}
global Void execute(Database.BatchableContext bc, List<Account> Scope){
for(Account a :Scope){
a.Rating='client';
recordsProcessed = recordsProcessed + 1;
}
update Scope; }
global void finish(Database.BatchableContext bc){
System.debug(recordsProcessed + 'records processed. Shazam!');
}
}
test class
@isTest public class UpdateAccountRatingTest {
@testSetup static void setup() {
Account ac =new Account();
ac.Name = 'test';
ac.rating='prospect';
insert ac;
ac.Name = 'test';
ac.rating='client';
update ac; }
@isTest static void test() {
Test.startTest();
UpdateAccountRating uar = new UpdateAccountRating();
Id batchId = Database.executeBatch(uar);
Test.stopTest(); } }
Thanks in advance
Find your test class with 100% Coverage and with best practice.
don't forget to mark it as the best answer.
Thank you
All Answers
try with below code.
If this helps, Please mark it as best answer.
Thanks!!
start method ,soql and finish methods are not covered. thanks in advance
try with below code getting 100%
If this helps, Please mark it as best answer.
Thanks!!
Find your test class with 100% Coverage and with best practice.
don't forget to mark it as the best answer.
Thank you