You need to sign in to do that
Don't have an account?
Jenifer Alonzo 23
Test class for page reference - only getting 28% Code Coverage
I'm working on a VF form that will allow users to quickly enter information, save, and return to a blank form. I have everything working but I can't figure out how to get test coverage on the controller extension. Many thanks for the help.
Here's the class:
Here's the test:
Here's the class:
public class saveAndNew{ ApexPages.StandardController sController; public saveAndNew(ApexPages.StandardController controller) { sController = controller; } public PageReference save() { sController.save(); PageReference pg = new PageReference('/apex/Workforce_Contact_Quick_Entry'); pg.setRedirect(true); return pg; } }
Here's the test:
@isTest private class saveAndNewTest { static testMethod void testQuickContact() { Contact myContact = new Contact (); myContact.lastname ='Test'; myContact.ownerId = UserInfo.getUserId(); insert myContact; Test.StartTest(); ApexPages.StandardController sc = new ApexPages.StandardController(myContact); saveAndNew testQuickContact = new saveAndNew(sc); PageReference pg = Page.Workforce_Contact_Quick_Entry; Pg.getparameters.put(); test.setCurrentPage(pg); Test.setCurrentPage(pg); sc.save(); } }
please call save method and check once.
Hope this helps you!
Thanks
Varaprasad
For Support: varaprasad4sfdc@gmail.com
All Answers
please call save method and check once.
Hope this helps you!
Thanks
Varaprasad
For Support: varaprasad4sfdc@gmail.com
Thank you so much for your help. It looks like the save part passes. It's the PageReference part that isn't passing. Is it possible to help with this bit of test code? I appreciate any help you can offer.
Here's the pageReference test that worked. I used Varaprasad's code to voer the save as it was more elegant than mine.
PageReference testPage = Page.Workforce_Contact_Quick_Entry;
Test.setCurrentPage(testPage);