I am trying to write a test class. I am clueless but with help from a buddy I have 32% so far.
The following code snippet is red b/c I don't have coverage for it yet.
What is SF expecting me to write in my test class to get the code covered? Also, what am I supposed to assert?
The code checks field in a given record and if it is blank, remove all records in the related list that had an id in that field (it was a string with record id's)
Thanks
This is the code in the actual class
if ( currentQ.Selected_Contacts_Ids_List__c == Null || currentQ.Selected_Contacts_Ids_List__c == '')
{
List <training__c> rd = [Select ID FROM training__c WHERE Training_Resource__c = :currentQ.Id];
delete rd;
return null;
}
This is a snippet in the test class that is relevant to this. Where to set currentQ.Selected_Contacts_Ids_List__c to Null or '' so it will get to the code that is not covered?
@isTest
public class test_Training_Students
{
@testSetup static void test_selectStudents()
{
Account account = new Account();
account.Name='Jas Training Ctr';
insert account;
Contact contactInterviewee = new Contact();
contactInterviewee.FirstName = 'test747';
contactInterviewee.LastName = 'test747';
contactInterviewee.Accountid = account.id;
contactInterviewee.RecordTypeid='012G0000001IiGfIAK';
contactInterviewee.Active_Candidate__c=true;
insert contactInterviewee;
Contact contactInterviewer = new Contact();
contactInterviewer.FirstName = 'test2';
contactInterviewer.LastName = 'test2';
//contactInterviewer.Account = account;
contactInterviewer.Accountid = account.id;
insert contactInterviewer;
Additional_Contact_Role__c acr = New Additional_Contact_Role__c();
acr.Name='TestACR';
acr.recordtypeid = '012G0000000nFlf';
insert acr;
List <Training_Resource__c> trL = New List<Training_Resource__c>();
Integer x;
for (x=1;x<3;x++)
{
Training_Resource__c tr = New Training_Resource__c();
tr.Name = 'Test'+x;
tr.Selected_Contacts_Ids_List__c = contactInterviewer.id + ','+ contactInterviewer.id;
RecordTypeId
Id
Coordinator_Name__c
Active__c
trL.add(tr);
}
insert trL;
for (x=0;x<2;x++)
{
Training__c trn = New Training__c();
trn.Name = 'A'+1;
trn.Sch__c = contactInterviewee.Id;
trn.Training_Resource__c= trL[x].id;
insert trn;
}
}
static testMethod void test_Training_Students()
{
Test.setCurrentPageReference(new PageReference('Page.vf_Training_Students'));
cls_Training_Students controller;
LIST <Training_Resource__c> trList = [SELECT ID From Training_Resource__c LIMIT 1];
Apexpages.StandardController sc = New apexpages.StandardController(trList[0]);
Test.startTest();
controller = new cls_Training_Students(sc);
controller.clearAllContacts();
controller.saveAllContacts();
controller.updateContactSelection();
controller.addTraining();
controller.init();
String currentContacts_CSV = trList[0].Id;
List <Training_Resource__c> trL = New List<Training_Resource__c>();
Integer x;
for (x=1;x<3;x++)
{
Training_Resource__c currentQ = New Training_Resource__c();
currentQ.Name = 'Test'+x;
currentQ.Selected_Contacts_Ids_List__c = '';
trL.add(currentQ);
}
Test.stopTest();
}
}
}