How can I determine via the APIs that an Apex class contains test cases?
I can query ApexClass, but there is no immediate field indicating the class contains tests.
Assuming the body field content is available (not from a managed package), do I need to manually search the contents of the Body field?
Attribution to: Daniel Ballinger
Possible Suggestion/Solution #1
As far as I know there's no field to indicate the presence of test methods.
I think you're right, you'll have to scan the code by searching the body field manually (since long text fields aren't available for filtering in SOQL) for the testmethod
keyword and @IsTest
annotation.
You may want to cater for commented varieties too, though this might be overcomplicating the situation.
SOSL Example to find (potential) classes containing tests.
FIND {@IsTest or testMethod} IN ALL FIELDS RETURNING ApexClass(Id, Name)
Attribution to: Matt Lacey
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/372