+ Start a Discussion
mac adminmac admin 

Test class for standard controler extension methods

Hi all,

I have written the test class for the standard controller extention. While I test run the test class the methods are failed. Below is my test class .

@istest
public class gdaControllerExtension_test {  
static testMethod void testreparentMethod()     {    
 GFrm__c gform = [SELECT ID FROM GFrm__c LIMIT 1];     ApexPages.StandardController stdController = new ApexPages.StandardController(gfrm);     gdaControllerExtension gdcon=new gdaControllerExtension(stdController);     
    gdcon.gfrm.SelectProgram__c='MA';
 gdcon.mfarten();   
}   
static testMethod void testparentreAddresMethod()     {     
GFrm__c gform = [SELECT ID FROM GFrm__c LIMIT 1];     ApexPages.StandardController stdController = new ApexPages.StandardController(gfrm);     gdaControllerExtension gdcon=new gdaControllerExtension(stdController);           
    gdcon.gfrm.SelectProgram__c='AED';
  gdcon.mfarten();   
}       
static testMethod void testparentresetAddressMethod()     {     
GFrm__c gform = [SELECT ID FROM GFrm__c LIMIT 1];     ApexPages.StandardController stdController = new ApexPages.StandardController(gfrm);     gdaControllerExtension gdcon=new gdaControllerExtension(stdController);     
     gdcon.gform.SelectProgram__c='Re-enroll';
 gdcon.mfarten();
  }
}


Can anyone help me over here.

Thanks in advance.

Regards,
mac.
Ashish KeshariAshish Keshari
I see the test methods does not seems to be appropriate. I see you are setting the value of a field 'SelectProgram__c' of a child object 'gfrm' of parent - 'gform' but you are not querying it. To use a field in an object - you need to query as well. So update your SOQL statement 
GFrm__c gform = [SELECT ID FROM GFrm__c LIMIT 1];