How to export Apex Test Class Coverage

Published by

on


If you want to export a report like below, then its very simple and in a minute you can get the same.

Just follow below steps:

  1. Go to Setup -> Apex Test Execution -> Click on ‘Select Tests…’ -> Click the checkbox next to Class Name -> Click on ‘Run’
    • NOTE: This is to Run All Test Classes to get Org Test Class Report
  2. Now Wait till all Test Class runs
  3. Now open any Data Export tool, in this example I will use Salesforce Inspector (you can use Data Loader)
  4. In Salesforce Inspector, Click on Export and Run below Query
    • SELECT ApexClassorTrigger.Name, NumLinesCovered,NumLinesUncovered FROM ApexCodeCoverageAggregate order by ApexClassorTrigger.Name asc
  5. Now copy the result or export to a CSV/excel like below:
  6. And at the Last Column, in this example its Column ‘D’ , paste this formula :: =ROUND((B2/(B2+C2))*100,0)
  7. Now you need to copy the formula in all rows of Column D. (This can be done by double clicking at buttom corner of D2 cell or drag the cell to other rows. )
  8. And your report is ready