Test.startTest() and Test.stopTest() are very useful when your test class hits Salesforce Governor Limits. These methods can be used to reset the governor limits within a test class.
The code inside Test.startTest() and Test.stopTest() have new set of Salesforce Governor Limits.
As a good practice, make sure initializing the variables, fetching records, creating and updating records are coded before Test.startTest() and Test.stopTest() and calling the controllers for code coverage is
done inside Test.startTest() and Test.stopTest(). The code before Test.startTest() and after Test.stopTest() have new set of Salesforce Governor Limits and code between Test.startTest() and Test.stopTest() have new set of Salesforce Governor Limits.
Example Test Class:
private class ExampleTestClass {
static TestMethod void test() {
/*
Declare the variables, Fetch the required records, Create and update sample records
*/
/*
Test.startTest();
/*
Call the controller for code coverage
*/
Test.stopTest();
*/
}
}
No comments:
Post a Comment