1

I am trying to set up a CICD validation which needs to check if the test code coverage is going below 85% on a Pull Request. I am using the below SFDX deploy command but it doesn't give me code coverage in the result.

sfdx force:source:deploy -u testscratchorg1 -p force-app\main\default --checkonly --testlevel RunLocalTests --json

Has anyone implemented something like this before or any suggestions??

Thank you in advance!

1 Answer 1

2

Deployments used to emit coverage data, but that changed in some recent-ish version.

To get coverage/failed test information now, you need to add the --verbose flag

If you're using the --json flag to output results as JSON, the coverage information is contained in result -> details -> runTestResult -> codeCoverage. The "numLocations" gives you the total number of coverable lines for a class, and the "numLocationsNotCovered" gives you the number of lines not covered.

You'll need to calculate the percentage yourself (1 - uncovered/total)

If you're using the --json flag, it appears that you don't need --verbose. --verbose seems to add to the printed information written to std out (i.e. the console/terminal/command-line)

2
  • Derek, I have used --verbose. Can you point out to me in the response where I can find the test coverage? It just shows a message if the test class has less than 75%. "codeCoverageWarnings": { "id": "01p0U00000FKl9D", "message": "Test coverage of selected Apex Class is 0%, at least 75% test coverage is required", "name": "ParentQuestion", "namespace": { "$": { "xsi:nil": "true" } } } Commented Jan 25, 2022 at 0:48
  • @Numaan Took me a while to be able to do a deployment myself to check this. I've edited my answer with my findings.
    – Derek F
    Commented Jan 25, 2022 at 17:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .