Can you clarify how Test.startTest() and Test.stopTest() work? I would have thought the limits in the code below would have produced 1 soql query, and instead I'm seeing 100.
Code:
public static testmethod void test123(){
for (integer i = 0; i < 99; i++){
List <account> accts = [select name from Account];
}
Test.startTest();
List <account> accts = [select name from Account];
system.debug('made it here');
Test.stopTest();
system.debug('done');
}
Debug Logs
00:37:18.486 (5486903866)|LIMIT_USAGE_FOR_NS|(default)|
Number of SOQL queries: 100 out of 100 ******* CLOSE TO LIMIT
Number of query rows: 0 out of 50000
Number of SOSL queries: 0 out of 20
Number of DML statements: 0 out of 150
Number of DML rows: 0 out of 10000
Maximum CPU time: 0 out of 10000
Maximum heap size: 0 out of 6000000
Number of callouts: 0 out of 100
Number of Email Invocations: 0 out of 10
Number of future calls: 0 out of 50
Number of queueable jobs added to the queue: 0 out of 50
Number of Mobile Apex push calls: 0 out of 10
00:37:18.486 (5486903866)|TESTING_LIMITS
00:37:18.486 (5486903866)|LIMIT_USAGE_FOR_NS|(default)|
Number of SOQL queries: 0 out of 100
Number of query rows: 0 out of 50000
Number of SOSL queries: 0 out of 20
Number of DML statements: 0 out of 150
Number of DML rows: 0 out of 10000
Maximum CPU time: 0 out of 10000
Maximum heap size: 0 out of 6000000
Number of callouts: 0 out of 100
Number of Email Invocations: 0 out of 10
Number of future calls: 0 out of 50
Number of queueable jobs added to the queue: 0 out of 50
Number of Mobile Apex push calls: 0 out of 10