2

I've seen the SFDX_IMPROVED_CODE_COVERAGE environment variable be used, but I don't understand what it does. Googling SFDX_IMPROVED_CODE_COVERAGE gives practically no results. What does SFDX_IMPROVED_CODE_COVERAGE do?

I see it used in examples like this SFDX_IMPROVED_CODE_COVERAGE='true' sfdx force:apex:test:run --outputdir build/reports/apexunit --codecoverage

1 Answer 1

2

The Spring '20 release notes contains information from when this was introduced and how it calculates different coverage numbers due to the fact it's scoped to the actual test execution run (vs. pulling coverage from across multiple test runs).

We improved the force:apex:test:run and force:apex:test:report commands to provide more accurate code coverage results. Previously, running these commands with the codecoverage flag returned results across multiple test runs. Now, the results show only the classes that a test execution entered during the run. And, the coverage calculations factor only these classes.

How: The code coverage results are now scoped to the tests in a given test run. For example, if you run TestClassA and TestClassB, and TestClassA executes code only in ClassA and TestClassB executes only ClassB. The code coverage result for the first run includes only ClassA, and the second run includes only ClassB.

To enable this new behavior, set the environment variable SFDX_IMPROVED_CODE_COVERAGE to true. When you run the force:apex:test:run and force:apex:test:report CLI commands after enabling the new behavior, you’ll notice changes in your code coverage numbers. The new numbers reflect a more accurate code coverage result.

Likewise, Environment Variables for the CLI are documented:

Scopes Apex test results to the classes entered during a test run when running force:apex:test:run and force:apex:test:report. Set to true to improve code coverage.

You must log in to answer this question.

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