You need to sign in to do that
Don't have an account?

I need a test class for the following extension class. Can anyone help me with this...
public class my_extension {
public TCOM__c t;
ApexPages.StandardController sController;
public my_extension(ApexPages.StandardController controller) {
sController = controller;
t= (TCOM__c )controller.getRecord();
}
public ApexPages.PageReference saveNew(){
sController = new ApexPages.StandardController(t);
PageReference p=null;
try{
sController.save();
p=new PageReference('/apex/vf40');
p.setRedirect(true);
}
catch(Exception e) {
return null;
}
return p;
}
}
public TCOM__c t;
ApexPages.StandardController sController;
public my_extension(ApexPages.StandardController controller) {
sController = controller;
t= (TCOM__c )controller.getRecord();
}
public ApexPages.PageReference saveNew(){
sController = new ApexPages.StandardController(t);
PageReference p=null;
try{
sController.save();
p=new PageReference('/apex/vf40');
p.setRedirect(true);
}
catch(Exception e) {
return null;
}
return p;
}
}
All Answers
1) https://trailhead.salesforce.com/modules/apex_testing
Pleasse check below post sample test class
1) http://amitsalesforce.blogspot.com/2015/06/best-practice-for-test-classes-sample.html
Also please check below post
1) https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_qs_test.htm
2) https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_example.htm
You write a test class for this the same way that you would any other:
- Set up some data for the Apex to access
- Verify the behaviour with asserts.
Try to update the code like below
NOTE:- You need to pass StandardController object in my_extension.
Thanks Alot !