0

I have a test class which is just inserting few object records. It does not have any test.startTest()/Test.StopTest(); . Neither it is instantiating any other class. How to know that which classes are covered by this test class ? And the percentage of each classes that is covered.

2

I believe you can use tooling API to find out which classes are covered by a particular TESTCLASS and TESTMETHOD. But first make GOTO Setup > Apex Test Execution > Options and make sure that `Store aggregate test coverage only' is turned OFF.

Test Coverage

Then go-to Workbench > Utilities > Rest Explorer. and use tolling API to query ApexCodeCoverage object.

/services/data/v36.0/tooling/query?q=SELECT+ApexClassorTriggerId,NumLinesCovered,NumLinesUnCovered+FROM+ApexCodeCoverage+where+ApexTestClassId='ADD_YOUR_TEST_CLASS_ID_HERE'

It will give you Id of the class it covers and number of lines covered and uncovered of all classes and triggers. You can calculate the percentage using by using

(NumLinesCovered*100/NumLinesCovered+NumLinesUnCovered)

enter image description here

|improve this answer|||||
1

The simple answer to your question is No and No (as of now .. may be it will change in future)

You will not be able to easily find the % covered by specific test class. You can find which classes are covered and to what percent(but not by which test class).

You can not also find which classed are tested by your test class. You will have to read your test class and find out which trigger and classed are getting executed.

There are few partial workaround thought for 2nd point above.
1) You can look at debug log and find the trace of all classes & triggers
2) If your test fail it will give your trace of classes

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.