function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
John NeilanJohn Neilan 

Test Custom Controller

Hello,

I'm having trouble getting adequate test coverage for a custom VF controller I created.  My test and controller are below.  When I run the test, I am getting no coverage for lines 13, 16-17, and 26-46.  Can anyone point me to what I need to do to get these lines covered?  The VF page works properly when tested.  Thanks

Test Class:
@Istest(SeeAllData=true)
public class TestVFControllers {

    public static testMethod void testCQ1() {
    
        User user1 = TestCreateRecords.createAMUser();
        insert user1;

        Account acct1 = TestCreateRecords.createAcct(0);
        insert acct1;
  
        Client_Questionnaire__c cq1 = TestCreateRecords.createCQ(acct1.Id);
 
        ApexPages.StandardController sc1 = new ApexPages.standardController(acct1);
        VF_CQController cqCont = new VF_CQController(sc1);
        cqCont.cq.add(cq1);
        cqCont.save();
    
    }
}



Controller:
public class VF_CQController{

public List<Client_Questionnaire__c> cq {get; set;}

    private final Account acct;
    public VF_CQController(ApexPages.StandardController myController){
        cq = new List<Client_Questionnaire__c>();
        acct=(Account)myController.getrecord();
system.debug('*##***** acct: ' + acct);
    }

    public Client_Questionnaire__c cq2 = new Client_Questionnaire__c();
        public void clientQuest(){
       
system.debug('*##*****:'+cq2);
            cq2.Account_Name__c = acct.id;
            cq.add(cq2);
system.debug('*##***** Account Name: '+cq2.Account_Name__c);   
        }
    
    public PageReference save() {
        IF(cq2.Initial_Meeting_Date__c == null){
            cq2.Initial_Meeting_Date__c.addError('Please enter the date of the initial meeting you have with this client');
            return null;
        }
        IF(cq2.Primary_Goal__c == null){
            cq2.Primary_Goal__c.addError('Please enter the Primar Goal for this client');
            return null;
        }
        IF(cq2.Training__c == null){
            cq2.Training__c.addError('Please enter the initial training you have set up for this client');
            return null;
        }
        IF(cq2.Training_Availability__c == null){
            cq2.Training_Availability__c.addError('Please enter the client&rsquo;s availability for training');
            return null;
        }
        IF(cq2.Recurring_Meeting__c == null){
            cq2.Recurring_Meeting__c.addError('Please enter the recurring meeting schedule set up for this client');
            return null;
        }    
    insert cq;
        {
        PageReference RetPage = new PageReference('/apex/ClientQuestInitVerify?id=' + cq[0].id);
        RetPage.setRedirect(true);
        return RetPage; 
        }
    }
}

 
Shaijan ThomasShaijan Thomas
@Istest(SeeAllData=true)
public class TestVFControllers {

    public static testMethod void testCQ1() {
    
        User user1 = TestCreateRecords.createAMUser();
        insert user1;

        Account acct1 = TestCreateRecords.createAcct(0);
        insert acct1;
  
        Client_Questionnaire__c cq1 = TestCreateRecords.createCQ(acct1.Id);
 
        VF_CQController cqCont = new VF_CQController(new ApexPages.standardController(acct1));
        cqCont.cq.add(cq1);
        cqCont.save();
		
		cq1.Initial_Meeting_Date__c ='Test';
		update cq1;
		VF_CQController cqCont1 = new VF_CQController(new ApexPages.standardController(acct1));
		cqCont1.cq.add(cq1);
        cqCont1.save();
		
		cq1.Primary_Goal__c ='Test';
		update cq1;
		VF_CQController cqCont2 = new VF_CQController(new ApexPages.standardController(acct1));
		cqCont2.cq.add(cq1);
        cqCont2.save();
		
		cq1.Training__c  ='Test';
		update cq1;
		VF_CQController cqCont3 = new VF_CQController(new ApexPages.standardController(acct1));
		cqCont3.cq.add(cq1);
        cqCont3.save();
		// Set other two values like this
    
    }
}

Can you try this
Shaijan Thomas