You need to sign in to do that
Don't have an account?
GregNYC
Apex Test Coverage Assistance
Hello,
I'm new to Apex development, and while my class and visualforce page are working nicely, I'm a bit at a loss for getting Test Coverage working.
My class:
public class FlowReference { private final Program__c program; public FlowReference() { program = [select id, name, Product_Summary__c, Position1_Item__r.Name, Position2_Item__r.Name, Position1_Item__r.FAQ__c, Position2_Item__r.FAQ__c, Customer_Service_Info__c from Program__c where id = :ApexPages.currentPage().getParameters().get('id')]; } public Program__c getProgram() { return program; } //TEST COVERAGE public static testMethod void testFlowReference() { //Create program Program__c p = new Program__c(name='Test Program'); insert p; p.CampaignID__c = '123'; update p; FlowReference class1 = new FlowReference(); class1.name = p.CampaignID__c; // I know this is wrong!! Program__c updatedProgram = [SELECT CampaignID__c FROM Program__C WHERE Id = :p.Id]; System.assertEquals('123', updatedProgram.CampaignID__c); } }
I know things go bad around class1.name = p.CampaignID__c...
Any help is appreciated!
Thanks.
Hi,
You can write your testMethod as follows:
You may face some issues as I dont knwo the exact object model that you have.
Also as a best practice you should avoid writing the code in constructor of the controller as you will not be able to control the execution of the constructor instead you can use "action" attribute of VF Page which will be called on PageLoad.
Also there are lots of best practices for TestMethods that you should follow, that will help you in writing proper test cases. You can read more about Test Methods by going to following link
http://wiki.developerforce.com/index.php/An_Introduction_to_Apex_Code_Test_Methods
If you need further assistance, please feel free to post it here.