You need to sign in to do that
Don't have an account?
John Neilan
Test to Cover Page Redirect in VF Controller
Hello,
I have a custom VF controller and I'm trying to write some line in my test that will cover the Save and page redirect sections of the controller (lines 21-24 below). Can anyone help me figure out the test code that will cover the page redirect? Thanks,
Controller
Test Class
I have a custom VF controller and I'm trying to write some line in my test that will cover the Save and page redirect sections of the controller (lines 21-24 below). Can anyone help me figure out the test code that will cover the page redirect? Thanks,
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(); } public Client_Questionnaire__c cq2 = new Client_Questionnaire__c(); public void clientQuest(){ cq2.Account_Name__c = acct.id; cq.add(cq2); } public PageReference save() { insert cq; { PageReference RetPage = new PageReference('/apex/ClientQuestInitVerify?id=' + cq[0].id); RetPage.setRedirect(true); return RetPage; } } }
Test Class
@IsTest public class TestVFControllers { static testMethod void Test_CQ_Overall() { User user1 = TestCreateRecords.createAMUser(); insert user1; Account acct1 = TestCreateRecords.createAcct(0); insert acct1; Client_Questionnaire__c cq1 = TestCreateRecords.createCQNull(acct1.Id); ApexPages.StandardController sc1 = new ApexPages.standardController(acct1); VF_CQController cqCont1 = new VF_CQController(sc1); cqCont1.cq.add(cq1); Test.StartTest(); cqCont1.clientQuest(); Test.StopTest(); }
Try using your or Karanraj' code but with a slight modification in your controller (it will not affect its behavior):
Regards.
Don't forget to mark your thread as 'SOLVED' with the answer that best helps you.