You need to sign in to do that
Don't have an account?
Nishad Basha
How write the Test class for batch apex?
how write the Test class for batch apex we need for our requirement.ple
ase give some ideas.
global class bchrankupdate implements database.batchable<sObject>{ List<Batchrank__c> newbatchmark = new List<Batchrank__c>(); global database.querylocator start(database.BatchableContext BC){ String Query = 'SELECT name, Percents__c, TestRanks__c, Rank__c FROM Batchrank__c'; return Database.getQueryLocator(query); } global void execute(database.BatchableContext BC, List<Batchrank__c> s){ system.debug('batch size:'+s.size()); for(Batchrank__c br : s){ system.debug('record:'+br); if(br.Percents__c >= 90 && br.Percents__c <= 100){ if(br.TestRanks__c=='First') { br.Rank__c = '1'; newbatchmark.add(br); }else{ br.Rank__c = 'Empty'; newbatchmark.add(br); } }else if(br.Percents__c >= 80 && br.Percents__c <= 89){ if(br.TestRanks__c=='Second'){ br.Rank__c = '2'; newbatchmark.add(br); }else{ br.Rank__c = ' '; newbatchmark.add(br); } }else if(br.Percents__c >= 70 && br.Percents__c <= 79){ if(br.TestRanks__c=='Third'){ br.Rank__c = '3'; newbatchmark.add(br); }else{ br.Rank__c = ' '; newbatchmark.add(br); } }else if(br.Percents__c >= 60 && br.Percents__c <= 69){ if(br.TestRanks__c=='Fourth'){ br.Rank__c = '4'; newbatchmark.add(br); }else{ br.Rank__c = ' '; newbatchmark.add(br); } }else if(br.Percents__c >= 40 && br.Percents__c <= 59){ if(br.TestRanks__c=='Fifth'){ br.Rank__c = '5'; newbatchmark.add(br); }else{ br.Rank__c = ' '; newbatchmark.add(br); } } update newbatchmark; } } global void finish(database.batchablecontext BC){ } }
ase give some ideas.
https://developer.salesforce.com/docs/atlas.en-us.apex_workbook.meta/apex_workbook/apex_batch_2.htm
All Answers
https://developer.salesforce.com/docs/atlas.en-us.apex_workbook.meta/apex_workbook/apex_batch_2.htm
i need apex code coverage for 75%. for below code .how can i achieve please give some ideas.
You have lots of conditions if else so you have to make sure that you create data to execute all these conditions. You could create multiple test methods with appropriate data for conditions so overall coverage by all methods will increase.
Thanks
Shashikant
i need apex code coverage for 75%. how can i achieve please give some ideas.
Hi, Shashikant Sharma
i need apex code coverage for 75%. can you give me above code modification for example
Hi, Shashikant Sharma
can you give me above code modification for example. apex code coverage for 75%.
Hi, Shashikant Sharma
without using if condition else how to run the above test class .please send me related code.