You need to sign in to do that
Don't have an account?
TestStop & test start methd
hello,
i want to know the use of TestStop & test start methd.
here is my working test class without testStop Method
TEST CLASS
@isTest
Private class testChildCount{
static testMethod void testoFChildCount(){
Account acc1=new Account();
acc1.name='Tej1';
acc1.childCount__c=0;
insert acc1;
System.assertEquals(0,acc1.childCount__c);
Account acc2=new Account();
acc2.name='Tej2';
acc2.ParentId=acc1.id;
acc2.childCount__c=0;
insert acc2;
Account acc=[select childCount__c from account where id=: acc1.id ];
System.assertEquals(1,acc.childCount__c);
delete acc2;
acc=[select childCount__c from account where id=: acc1.id ];
System.assertEquals(0,acc.childCount__c);
Account acc3=new Account();
acc3.name='Tej3';
acc3.childCount__c=0;
insert acc3;
Account acc4=new Account();
acc4.name='Tej4';
acc4.childCount__c=0;
acc4.ParentId=acc1.id;
insert acc4;
acc=[select childCount__c from account where id=: acc1.id ];
System.assertEquals(1,acc.childCount__c);
acc=[select childCount__c from account where id=: acc4.id ];
acc.ParentId=acc3.id;
update acc;
acc=[select childCount__c from account where id=: acc1.id ];
System.assertEquals(0,acc.childCount__c);
acc=[select childCount__c from account where id=: acc3.id ];
System.assertEquals(1,acc.childCount__c);
}
}
There are two additional system static methods provided by Apex. These methods, Test.startTest and Test.stopTest, are used when testing governor limits. Or in other words, executing test scenarios with a larger data set.
The Test.startTest method marks the point in your test code when your test actually begins. Each test method is allowed to call this method only once. All of the code before this method should be used to initialize variables, populate data structures, and so on, allowing you to set up everything you need in order to run your test. After you call this method, you get a fresh set of governor limits for the remainder of the test until you call Test.stopTest.
The Test.stopTest method marks the point in your test code when your test ends. Use this method in conjunction with the startTest method. Each test method is allowed to call this method only once. After calling this method, any post assertions are done in the original context.
Refer : http://wiki.developerforce.com/page/An_Introduction_to_Apex_Code_Test_Methods
If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.