function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ram ChaturvediRam Chaturvedi 

Testing Already Started ....?

@isTest
public class govenerLimit {
    public static testMethod void main(){        
        for(integer i =0 ; i<101 ; i++){           
            test.startTest();
            list<student__c> sts = [select name from student__c];
            test.stopTest();          
        } 
    }
}   
//----------- above code execute Successfully .

@isTest
public class govenerLimit
    public static testMethod void main(){
        for(integer i =0 ; i<101 ; i++){           
            test.startTest();
            list<student__c> sts = [select name from student__c];
            test.stopTest();          
        }
            test.startTest();
            list<faculty__c> facs = [select name from faculty__c];
            test.stopTest();
    }
} // -------- But this code gives msg-------- "Testing Already Started" ---------  why ?

BalajiRanganathanBalajiRanganathan
According the doc, each test method can call the test.startTest() only once.

https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_test.htm#apex_System_Test_startTest

you have to create two test methods instead of one. also I am not sure why you want to call the test.startTest() inside for loop

 
Ram ChaturvediRam Chaturvedi
But in my first ex i am putting startTest in loop , means it calls many times but in that case it is not giving any type of error .