Need code coverage to depoy, but cannot test.@isTest
private class ListViewControllerTest {
/**This is the list which will be passed to Visualforce Page and in turn passed to Flow from Visualforce**/
public List<Matching_Facility__c> LstSelectedFacilities { get; set; }
public ListViewControllerTest(ApexPages.StandardSetController listcontroller) {
Set<Id> facilitySelectedIds = new Set<Id>();
LstSelectedFacilities = new List<Matching_Facility__c>();
for (Matching_Facility__c f : (Matching_Facility__c[])listcontroller.getSelected()) {
facilitySelectedIds.add(f.Id);
}
/**Querying on the Selected records and fetching fields which are required in Flow **/
LstSelectedFacilities = [SELECT Id, Client_Search__c FROM Matching_Facility__c WHERE Id IN :facilitySelectedIds];
}
}
Hello Patrick ,Based on the code snippet you provided, the ListViewControllerTest class seems to be a constructor with parameters, rather than a test class with test methods.To add test methods, you can create a separate test class that will create an instance of ListViewControllerTest and test its functionality. Please try with the below and let me know if you face any difficulties :
If this helps , please mark this as Best Answer.Thank you.@isTest
private class ListViewControllerTest_Test {
@isTest
static void testListViewControllerTest() {
// Create test data
Matching_Facility_c facility = new Matching_Facilityc(Client_Search_c = 'Test Client Search');
insert facility;
// Create a standard set controller for the Matching_Facility__c object
ApexPages.StandardSetController controller = new ApexPages.StandardSetController(Database.getQueryLocator([SELECT Id FROM Matching_Facility__c]));
// Add the facility to the selected records
controller.setSelected(new List<Matching_Facility__c>{facility});
// Create an instance of ListViewControllerTest and verify the selected facilities are retrieved correctly
ListViewControllerTest testController = new ListViewControllerTest(controller);
System.assertEquals(1, testController.LstSelectedFacilities.size());
System.assertEquals(facility.Id, testController.LstSelectedFacilities[0].Id);
System.assertEquals(facility.Client_Search_c, testController.LstSelectedFacilities[0].Client_Search_c);
}
}