You need to sign in to do that
Don't have an account?
Creating and Fetching Test Data in Controller Extension
Hello friends,
I need your help in Test class writing for Controller extension.
I have written the test case for Controller extension. I have created all the Test data and suppliying the test record in constructor of controller extension.
I knew that in test class, nothing is inserted into database and we just get the ID of record.
When i try to fetch the test record in Test class itself it is working fine However when i try to use same query in Controller extension, no records are returned.
That means i am not able to use any test data in Controller extension.
Some code snap i am using :
static testMethod void testPaymentWizard_noApprovedAmount() { PageReference paymentPage = Page.PaymentWizard; //Create temp User User testUser = UtilTest.getProgramUser(); //Create temp data List<Opportunity> oppList = UtilTest.getProposal_PayWizard(); insert oppList; //Ensure that all 3 Opportunity inserted successfully System.assertNotEquals(oppList[0].Id, null); System.assertNotEquals(oppList[1].Id, null); System.assertNotEquals(oppList[2].Id, null); System.assertNotEquals(oppList[2].RecordTypeID,null); //Create temp data User pu = UtilTest.getProgramUser(); Test.setCurrentPage(paymentPage); Test.startTest(); System.runAs(pu) { //set some dependent test data UtilTest.setProposalStaff_PayWizard(oppList[0].Id,pu); ApexPages.StandardController sc = new ApexPages.StandardController(oppList[2]); sc = new ApexPages.StandardController(oppList[2]); pc = new PaymentController(sc); System.assertNotEquals(pc, null); //In this method Test data created is not available Pagereference firstPage = pc.processSelected(); } Test.stopTest(); }
Is something important i am missing here?
Thanks in advance.
It was so silly, Got the root cause :D
I was trying to access the record which was not inserted by current user.