Refer to below test class,
@isTest
public with sharing class CategoryHelperTest {
private static boolean testDataCreated = false;
private static Scheme__c ss;
private static Scheme__c ss2;
private static Scheme__c ss3;
private static Scheme__c ss4;
private static Scheme__c ss5;
private static Band__c sb;
private static Band__c sb2;
private static Band__c sb3;
private static Category__c ic;
private static Category__c ic2;
private static Category__c ic3;
private static Category__c ic4;
private static Category__c ic5;
private static Category__c ic6;
private static Category__c ic7;
private static Category__c ic8;
private static Category__c ic9;
private static Band_Entry__c sbe;
private static Band_Entry__c sbe2;
private static Band_Entry__c sbe3;
private String ErrorMessage;
public static void tester(){
ss = new Scheme__c(Name = 'TestScheme', Description__c = 'TestScheme');
insert ss;
ss2 = new Scheme__c(Name = 'TestScheme', Description__c = 'TestScheme2');
insert ss2;
ss3 = new Scheme__c(Name = 'TestScheme', Description__c = 'TestScheme3');
insert ss3;
ss4 = new Scheme__c(Name = 'TestScheme', Description__c = 'TestScheme4');
insert ss4;
ss5 = new Scheme__c(Name = 'TestScheme', Description__c = 'TestScheme5');
insert ss5;
ss6 = new Scheme__c(Name = 'TestScheme', Description__c = 'TestScheme6');
insert ss6;
ss7 = new Scheme__c(Name = 'TestScheme', Description__c = 'TestScheme7');
insert ss7;
ss8 = new Scheme__c(Name = 'TestScheme', Description__c = 'TestScheme8');
insert ss8;
ss9 = new Scheme__c(Name = 'TestScheme', Description__c = 'TestScheme9');
insert ss9;
ss10 = new Scheme__c(Name = 'TestScheme', Description__c = 'TestScheme10');
insert ss10;
sb = new Band__c(Name = 'Low', Colour__c = 'Green', Rating__c = 1, Type__c = 'Impact', Scheme__c = ss.id);
insert sb;
sb2 = new Band__c(Name = 'Low', Colour__c = 'Green', Rating__c = 1, Type__c = 'Likelihood', Scheme__c = ss.id);
insert sb2;
sb3 = new Band__c(Name = 'Medium', Colour__c = 'Amber', Rating__c = 2, Type__c = 'Likelihood', Scheme__c = ss.id);
insert sb3;
//Testing with 'Cost' & 'Time'
ic = new Category__c(Name = 'HR',Symbol__c = '?', Justification_Required__c='Inherent;Target', Type_of_Risk__c='Cost', Units__c = 'test', Scheme__c = ss.id);
insert ic;
ic2 = new Category__c(Name = 'HR',Symbol__c = '?', Justification_Required__c='Inherent;Target', Type_of_Risk__c='Time', Units__c = 'test', Scheme__c = ss.id);
insert ic2;
//Testing with 'Cost' & '%Time'
ic3 = new Category__c(Name = 'HR',Symbol__c = '?', Justification_Required__c='Inherent;Target', Type_of_Risk__c='Cost', Units__c = 'test', Scheme__c = ss2.id);
insert ic3;
ic4 = new Category__c(Name = 'HR',Symbol__c = '?', Justification_Required__c='Inherent;Target', Type_of_Risk__c='%Time', Units__c = 'test', Scheme__c = ss2.id);
insert ic4;
//Testing with '%Cost' & 'Time'
ic5 = new Category__c(Name = 'HR',Symbol__c = '?', Justification_Required__c='Inherent;Target', Type_of_Risk__c='%Cost', Units__c = 'test', Scheme__c = ss3.id);
insert ic5;
ic6 = new Category__c(Name = 'HR',Symbol__c = '?', Justification_Required__c='Inherent;Target', Type_of_Risk__c='Time', Units__c = 'test', Scheme__c = ss3.id);
insert ic6;
//Testing with '%Cost' & '%Time'
ic7 = new Category__c(Name = 'HR',Symbol__c = '?', Justification_Required__c='Inherent;Target', Type_of_Risk__c='%Cost', Units__c = 'test', Scheme__c = ss4.id);
insert ic7;
ic8 = new Category__c(Name = 'HR',Symbol__c = '?', Justification_Required__c='Inherent;Target', Type_of_Risk__c='%Time', Units__c = 'test', Scheme__c = ss4.id);
insert ic8;
sbe = new Band_Entry__c(Label__c = 'TestBandEntry', Description__c = 'TestScoreBandEntry', From_Value__c = 10, To_Value__c = 20, Band__c = sb.id, Category__c = ic.id );
insert sbe;
sbe2 = new Band_Entry__c(Label__c = 'TestBandEntry2', Description__c = 'TestScoreBandEntry2', From_Value__c = 10, To_Value__c = 20, Band__c = sb2.id, Category__c = ic.id );
insert sbe2;
sbe3 = new Band_Entry__c(Label__c = 'TestBandEntry3', Description__c = 'TestScoreBandEntry3', From_Value__c = 20, To_Value__c = 30, Band__c = sb3.id, Category__c = ic.id );
insert sbe3;
testDataCreated = true;
}
In the test method i'm using different ids to check different scenarios, but if I use a list as below, I can't use different ids for each 'TestScheme1', 'TestScheme2' etc to test different scenarios because all entries are in the list.
How can I get this test class written to test scenarios in the same way using a list or a map ?
public static void tester(){
List<Scheme__c> insertList = new List<Scheme__c>();
insertList.add(new Scheme__c(Name = 'TestScheme', Description__c = 'TestScheme'));
insertList.add(new Scheme__c(Name = 'TestScheme', Description__c = 'TestScheme2'));
insertList.add(new Scheme__c(Name = 'TestScheme', Description__c = 'TestScheme3'));
insertList.add(new Scheme__c(Name = 'TestScheme', Description__c = 'TestScheme4'));
insertList.add(new Scheme__c(Name = 'TestScheme', Description__c = 'TestScheme5'));
insert insertList;
}