We have been getting surprise random failures in our legacy Apex unit tests when certain types of modifications are made to process automation logic (usually new DML in triggers, flows, etc). I'm looking for ways to regularly monitor which Apex tests are closest to hitting SOQL and DML governor limits, so we can avoid these surprises.
Debug logs include information about usage vs. limits, but reading thousands of debug logs manually is not practical or repeatable. Do I have any other options?
Best Answer
As I was reading @sfdcfox's answer and considering why I felt it missed the mark a bit, I realized there's an approach that would meet my needs better.
The idea would be to create a test utility method that can be invoked from every test. A Boolean value in the utility (in my example,
doMonitoring
) can be toggled to force every test to fail artificially, and in the failure message, we report out on the usage stats.Sample utility class:
Sample usage
I see the following advantages of this approach over @sfdcfox's:
Test.startTest();
/Test.stopTest();
as well as those outside