Monitor Apex Test Setup Methods Using ApexTestResult

SF Connect
2 min readJun 12, 2024

In the past, it was only possible to get execution run times in Apex test class methods by looking at the ApexTestResult object which represented the result of an Apex test method execution. Previously, information about limits and cumulative run time was available only by parsing the appropriate method sections in the debug log. Starting Summer 24, rows are now generated for Apex tests run with the @testSetup annotation. A new IsTestSetup column is set to true for these annotated tests to distinguish them from other test methods. Also, a new TestSetupTime column on ApexTestRunResult tracks the cumulative time of all setup methods for the given ApexTestRunResult, similar to how TestTime tracks the cumulative time of all its test methods.

So after a test execution, you can now run a query like:

Select id, AsyncApexJobId, IsTestSetup, MethodName, Outcome, RunTime from ApexTestResult

ApexTestResult Represents the result of an Apex test method execution

Note the new IsTestSetup column along with the corresponding RunTime.

Running the following query and you will see summary information about all the test methods that were run in a particular Apex job as that is what ApexTestRunResult tracks.

SELECT Id, Source, AsyncApexJobId, MethodsCompleted, TestTime, TestSetupTime from ApexTestRunResult

This means that you can now benchmark Test Setup performance along with Test Methods. This can result in faster test class execution once you optimize the code. Happy refactoring :).

Originally posted at https://sf.watch

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

SF Connect
SF Connect

Written by SF Connect

Technical Architect @ SF Connect. Feel free to contact me for expert level Salesforce consulting, development, and staffing. https://sfconnect.com/contact/

No responses yet

Write a response