You need to sign in to do that
Don't have an account?
Pallavi singh
Need help to get the full 100% coverage for the batch class
Hi,
Need help to complete the test class
here is the batch class:
@isTest
private class CreateLeadDLCRecordsBatchTest {
@isTest
static void testBatchExecution() {
// Create test data
List<Lead> leads = new List<Lead>();
for (Integer i = 0; i < 10; i++) {
Lead lead = new Lead();
lead.FirstName = 'Test';
lead.LastName = 'Lead ' + i;
lead.Status = 'Converted';
// lead.Retention_Date_Reached__c = false;
leads.add(lead);
}
insert leads;
List<Lead_Status_History__c> leadStatusHistories = new List<Lead_Status_History__c>();
for (Lead lead : leads) {
Lead_Status_History__c history = new Lead_Status_History__c();
history.Lead__c = lead.Id;
// Set other required fields
leadStatusHistories.add(history);
}
insert leadStatusHistories;
// Start the batch
Test.startTest();
CreateLeadDLCRecordsBatch batch = new CreateLeadDLCRecordsBatch();
Database.executeBatch(batch);
Test.stopTest();
// Verify the results
Integer expectedDLCRecords = 10;
Integer actualDLCRecords = [SELECT COUNT() FROM DLC_Control__c];
System.assertEquals(expectedDLCRecords, actualDLCRecords, 'Incorrect number of DLC_Control__c records created');
Set<Id> expectedLeadStatusHistoryIds = new Set<Id>();
for (Lead_Status_History__c history : leadStatusHistories) {
expectedLeadStatusHistoryIds.add(history.Id);
}
Set<Id> actualLeadStatusHistoryIds = new Set<Id>();
for (DLC_Control__c dlc : [SELECT Record_Id__c FROM DLC_Control__c]) {
actualLeadStatusHistoryIds.add(dlc.Record_Id__c);
}
// System.assertEquals(expectedLeadStatusHistoryIds, actualLeadStatusHistoryIds, 'Incorrect Lead_Status_History__c records processed');
}
}
and this is my test class which covers 85% but i need 100%.
@isTest
private class CreateLeadDLCRecordsBatchTest {
@isTest
static void testBatchExecution() {
// Create test data
List<Lead> leads = new List<Lead>();
for (Integer i = 0; i < 10; i++) {
Lead lead = new Lead();
lead.FirstName = 'Test';
lead.LastName = 'Lead ' + i;
lead.Status = 'Converted';
// lead.Retention_Date_Reached__c = false;
leads.add(lead);
}
insert leads;
List<Lead_Status_History__c> leadStatusHistories = new List<Lead_Status_History__c>();
for (Lead lead : leads) {
Lead_Status_History__c history = new Lead_Status_History__c();
history.Lead__c = lead.Id;
// Set other required fields
leadStatusHistories.add(history);
}
insert leadStatusHistories;
// Start the batch
Test.startTest();
CreateLeadDLCRecordsBatch batch = new CreateLeadDLCRecordsBatch();
Database.executeBatch(batch);
Test.stopTest();
// Verify the results
Integer expectedDLCRecords = 10;
Integer actualDLCRecords = [SELECT COUNT() FROM DLC_Control__c];
System.assertEquals(expectedDLCRecords, actualDLCRecords, 'Incorrect number of DLC_Control__c records created');
Set<Id> expectedLeadStatusHistoryIds = new Set<Id>();
for (Lead_Status_History__c history : leadStatusHistories) {
expectedLeadStatusHistoryIds.add(history.Id);
}
Set<Id> actualLeadStatusHistoryIds = new Set<Id>();
for (DLC_Control__c dlc : [SELECT Record_Id__c FROM DLC_Control__c]) {
actualLeadStatusHistoryIds.add(dlc.Record_Id__c);
}
// System.assertEquals(expectedLeadStatusHistoryIds, actualLeadStatusHistoryIds, 'Incorrect Lead_Status_History__c records processed');
}
}
Thank you in advance
Need help to complete the test class
here is the batch class:
@isTest
private class CreateLeadDLCRecordsBatchTest {
@isTest
static void testBatchExecution() {
// Create test data
List<Lead> leads = new List<Lead>();
for (Integer i = 0; i < 10; i++) {
Lead lead = new Lead();
lead.FirstName = 'Test';
lead.LastName = 'Lead ' + i;
lead.Status = 'Converted';
// lead.Retention_Date_Reached__c = false;
leads.add(lead);
}
insert leads;
List<Lead_Status_History__c> leadStatusHistories = new List<Lead_Status_History__c>();
for (Lead lead : leads) {
Lead_Status_History__c history = new Lead_Status_History__c();
history.Lead__c = lead.Id;
// Set other required fields
leadStatusHistories.add(history);
}
insert leadStatusHistories;
// Start the batch
Test.startTest();
CreateLeadDLCRecordsBatch batch = new CreateLeadDLCRecordsBatch();
Database.executeBatch(batch);
Test.stopTest();
// Verify the results
Integer expectedDLCRecords = 10;
Integer actualDLCRecords = [SELECT COUNT() FROM DLC_Control__c];
System.assertEquals(expectedDLCRecords, actualDLCRecords, 'Incorrect number of DLC_Control__c records created');
Set<Id> expectedLeadStatusHistoryIds = new Set<Id>();
for (Lead_Status_History__c history : leadStatusHistories) {
expectedLeadStatusHistoryIds.add(history.Id);
}
Set<Id> actualLeadStatusHistoryIds = new Set<Id>();
for (DLC_Control__c dlc : [SELECT Record_Id__c FROM DLC_Control__c]) {
actualLeadStatusHistoryIds.add(dlc.Record_Id__c);
}
// System.assertEquals(expectedLeadStatusHistoryIds, actualLeadStatusHistoryIds, 'Incorrect Lead_Status_History__c records processed');
}
}
and this is my test class which covers 85% but i need 100%.
@isTest
private class CreateLeadDLCRecordsBatchTest {
@isTest
static void testBatchExecution() {
// Create test data
List<Lead> leads = new List<Lead>();
for (Integer i = 0; i < 10; i++) {
Lead lead = new Lead();
lead.FirstName = 'Test';
lead.LastName = 'Lead ' + i;
lead.Status = 'Converted';
// lead.Retention_Date_Reached__c = false;
leads.add(lead);
}
insert leads;
List<Lead_Status_History__c> leadStatusHistories = new List<Lead_Status_History__c>();
for (Lead lead : leads) {
Lead_Status_History__c history = new Lead_Status_History__c();
history.Lead__c = lead.Id;
// Set other required fields
leadStatusHistories.add(history);
}
insert leadStatusHistories;
// Start the batch
Test.startTest();
CreateLeadDLCRecordsBatch batch = new CreateLeadDLCRecordsBatch();
Database.executeBatch(batch);
Test.stopTest();
// Verify the results
Integer expectedDLCRecords = 10;
Integer actualDLCRecords = [SELECT COUNT() FROM DLC_Control__c];
System.assertEquals(expectedDLCRecords, actualDLCRecords, 'Incorrect number of DLC_Control__c records created');
Set<Id> expectedLeadStatusHistoryIds = new Set<Id>();
for (Lead_Status_History__c history : leadStatusHistories) {
expectedLeadStatusHistoryIds.add(history.Id);
}
Set<Id> actualLeadStatusHistoryIds = new Set<Id>();
for (DLC_Control__c dlc : [SELECT Record_Id__c FROM DLC_Control__c]) {
actualLeadStatusHistoryIds.add(dlc.Record_Id__c);
}
// System.assertEquals(expectedLeadStatusHistoryIds, actualLeadStatusHistoryIds, 'Incorrect Lead_Status_History__c records processed');
}
}
Thank you in advance
To achieve 100% test coverage for your batch class, you need to cover all possible execution paths and scenarios. Here's an example of how you can modify your test class to achieve full coverage:
Hope this will be Helpful.
Thanks!