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

Use Tooling API to query the names of all Test Classes

Is there a way to query the names of all test classes that exist in my Org using the  Tooling REST API? 



I was going through the Tooling API guide and did some research on this but don't think there is a direct way to get the list of test classes in an ORG

ApexCodeCoverage which represents code coverage test results for an Apex class or trigger does have a ApexTestClassId field but not sure if it can give the complete list if you run the query:
Surendra nuneSurendra nune

As all the test classes would be created starting/ending with "Test", you can query all test classes from ApexClass object by filtering on the name field. For details about the fields, please refer this link:
Arek Mazur (Hiszpan)Arek Mazur (Hiszpan)
I wanted to come back to this subject, because I faced problem like that few days ago, solution with querying by class name when class name contains 'test' wasn't satisfying for me, because what if some class has name 'TestUtil' and it's not a test class. I found solution, you can use tooling API and query ApexClass object like that:


On the picture I marked which property says that this is a test class, in non test class annotations list is empty. So all of information about classes you can find in SymbolTable object.
Rahul Agrawal 43Rahul Agrawal 43
you can fetch all the classes and their code coverage from any org and to extract the test classes there is not any direct way, instead you need to check from its name. PFB link