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
JconsultantJconsultant 

SOQL limit for Unit Tests

I have a Unit Test class that I am using to test 12 triggers.  I've noticed at the bottom of the debug log that I have used 93 of the 100 SOQL queries I'm allowed to use for a test pass.  Is there a way to split out the testing so that I don't run into this limit as I continue to develop in this environment and need to unit test my new code?  If I split the tests into seperate classes will that change the way the limits are evaluated when I run "all tests"?  My concern is that I'm going to add code and try to deploy it and even though it's test covered I'll hit this query limit.  Thoughts?

gv007gv007

In yous case when you are using for loop  limit the maximum for loop based on record.It you test case need to retrrive or do DML operation more then 100 records.

JconsultantJconsultant

Thanks Gopi.  That's not the issue though.  Imagine if you have 10 triggers with 10 SOQL queries in each.  If you have all of your unit tests in one test class then when they execute it will fire 100 SOQL queries as it runs through each trigger.  My question was, if you were to test 5 in one class and 5 in another would the limit be per class or for the total execution of ALL tests?

gv007gv007

I think from my experience I observed  it is counting  from code entry point to exit point.

SargeSarge

Hi,

   While unit testing you can use "test.startTest()" and "test.stopTest()" system methods to allocate a seperate testing resources when you run All tests. Like this you may solve your problem for some extent. Check out this link for more information.

 

Cheers..

ScoobieScoobie

From personal experience I'd not test more than one trigger at a time.

 

If you test multiple triggers in a unit test it makes debugging much harder when one of them fails. If you have multiple triggers firing on one event e.g. Before insert on account, consider putting all the code into methods in a Class and then unit testing the class. The trigger can then simply call out to that class at each point.