You need to sign in to do that
Don't have an account?
John 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:
Controller:
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’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; } } }
Can you try this
Shaijan Thomas