[SalesForce] Best tool for seeing highlighted covered Apex Code while writing test class

Currently I do most of my development in VScode using sfdx.

For writing test classes, I need to see which lines are covered in Apex classes I write.

In DX, running commands (see below) to get coverage result takes very long (perhaps more than three minutes when Apex test execution time is less than five seconds).

sfdx force:apex:test:run --classnames AnApexClass --resultformat json --outputdir d:\VScode projects\example\.sfdx\tools\testresults\apex --loglevel error --codecoverage

Therefore I usually use Developer Console for doing this job.
In Developer Console, the coverage result usually comes out right after the test methods finish executing. The downside of Developer console is that after each test run, I still need to find the Apex class I want by scrolling down in the "Overall Code Coverage" section. This is also quite time consuming when I need to run the test a couple of times.

I would like to ask if there is any way to make retrieving coverage result faster in DX?

Or, if there is any other tool better than Developer Console or DX?

Thanks.

Best Answer

Fortunately, there is an easier way to do this. I often use this while writing apex unit tests.

As mentioned in the comment by Kris, you can run specific or all test class methods from a class using the VS code.

To be able to see the code highlighted, you need to do enable it from the VS code bottom toolbar.

enter image description here

When you have that checked, you will be able to see the code coverage highlight in the VS Code for every test run.

Also, you will be able to see class wise coverage percentage (and line-wise) in the output panel of the VS code. There you can look for your specific classes coverage.

enter image description here


Also, you can invoke all tests, Test Suits, Specific Test classes using the command palette of the VS Code.

Just type 'Invoke Apex Tests' in the command palette, you will see all available test classes and suites to execute.

Related Topic