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 Class to access - Execute a method/methods:- - Verify the behaviour with asserts.
Sample code for you
@isTest
public class ExtensionTestClass
{
static testMethod void testMethod1()
{
Account testAccount = new Account();
testAccount.Name='Test Account' ;
insert testAccount;
Test.StartTest();
ApexPages.StandardController sc = new ApexPages.StandardController(testAccount);
myControllerExtension testAccPlan = new myControllerExtension(sc);
PageReference pageRef = Page.AccountPlan; // Add your VF page Name here
pageRef.getParameters().put('id', String.valueOf(testAccount.Id));
Test.setCurrentPage(pageRef);
//testAccPlan.save(); call all your function here
Test.StopTest();
}
}
Hi Vivek, For standard controllers you don't need to write test classes. Test classes for standard controllers are already present in the metadata repository of salesforce.
I will recommend you to start using trailhead to learn about test classes
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 Class to access
- Execute a method/methods:-
- Verify the behaviour with asserts.
Sample code for you
For standard controllers you don't need to write test classes. Test classes for standard controllers are already present in the metadata repository of salesforce.
Thanks.
You can do something like this Let me know if it helps
Thanks!