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
cristinacristina 

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? 

 

 

Sonam_SFDCSonam_SFDC
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:
http://www.salesforce.com/us/developer/docs/api_toolingpre/api_tooling.pdf
Surendra nuneSurendra nune
Cristina,

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:
https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_apexclass.htm
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:
 
/services/data/v37.0/tooling/query/?q=Select+Id,+SymbolTable+FROM+ApexClass

workbench

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
Hi,
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
http://technome2.blogspot.in/2017/04/sample.html