0

I have an org that has approx 530 test classes .I am currently working on a nodejs project that uses the sfdx commands to run the tests in the org and then generate code coverage report, analyze and classify them so that I can use the classified data to find what apex class lines are covered by which test classes/methods.

Since the amount of test classes are very large and salesforce removes coverage data if the records exceed 10K (which happens because of such a large amount of classes, triggers and test classes), I have tried to implement batches of tests to be run.

lets say the batch consists of Test_1,Test_2,.....,Test_10. The command I am using is given below.

sfdx force:apex:test:run --codecoverage -r json --classnames "Test_1,Test_2,.....,Test_10" -u testOrg --outputdir path/to/folder

The problem here is

  1. command blocks the script until the test are completed and overall coverage is calculated.
  2. after completion testRunId is not returned.
  3. with each subsequent run, previous test coverage data is also included in the output which is unrequired.

Is there anyway to run the command such that coverage data is only provided for the tests included in the batch?

Bonish Koirala
  • 641
  • 5
  • 16
  • For #3, how are you executing this command? in cicd? if yes which one, I have CICD in which we store the artefacts of particular run, so next run gives fresh data and old data is stored wrt old pipeline – Ysr Shk Sep 16 '20 at 17:58

2 Answers2

0

Try to seperate it to multicommands, what you will you gain this way ?

  1. The lock on the script done for small unit each time
  2. The result can be stored and analyzed seperate each class test

3. Previous test coverage data is NOT included in the output. each command calculate its test code coverage

 sfdx force:apex:test:run --codecoverage -r json --classnames "Test_1" -u testOrg --outputdir path/to/folder/Test_1

sfdx force:apex:test:run --codecoverage -r json --classnames "Test_2" -u testOrg --outputdir path/to/folder/Test_2

sfdx force:apex:test:run --codecoverage -r json --classnames "Test_10" -u testOrg --outputdir path/to/folder/Test_10
Brachy
  • 74
  • 6
0

Don't know if it's still relevant or not, but there is a solution.

You can overwrite the SFDX_MAX_QUERY_LIMIT environment variable's value and retrieve all records that you need.
From https://developer.salesforce.com/docs/atlas.en-us.sfdx_setup.meta/sfdx_setup/sfdx_dev_cli_env_variables.htm:
SFDX_MAX_QUERY_LIMIT
The maximum number of Salesforce records returned by a CLI command.
Default value is 10,000.
Example:
SFDX_MAX_QUERY_LIMIT=200000

  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/31025190) – tomerpacific Feb 13 '22 at 06:31