Skip to content

code coverage

Alan Ren edited this page Jul 20, 2022 · 2 revisions

Running Code Coverage

Code Coverage runs work on top of unit tests to ensure we have adequate coverage for key areas.

Run inside VSCode

To run inside VSCode, go to the Debug view, and choose Launch Code Coverage. This will execute all tests:

  • Results View tests, which run from the commandline.
  • Extension tests, which require launching a VSCode instance to run in

After running, we need to combine the coverage reports to be useful: run gulp cover:combine to produce a report located at coverage/lcov-report/index.html

Run from the commandline

Run gulp cover:jenkins to do a full code coverage run. This requires all VSCode instances be closed due to test framework limitations.

Using Code Coverage Results

Code Coverage is particularly good when writing new code. Please consider using it to ensure that your tests actually hit the important code paths you've added and that there aren't major gaps. Not all areas are testable, but a large number are and this will help keep us honest about how much of our code is tested.

View coverage report in a browser

After running coverage, opening the coverage/lcov-report/index.html file will allow you to see results in the browser. This helps give a baseline before you make changes, especially the raw coverage #s.

View code coverage numbers inline with your code

  • Install the VSCode LCOV extension to view
    • Relaunch VSCode
    • Hit F1 and choose LCOV Menu -> Enable Decorations
    • Navigate to the file you've added to and you should see uncovered lines in red. Very often the happy path is covered, but no other path has been covered
    • Add tests to fill in the gap areas, and re-run coverage so you can verify that you've hit all important branches and code sections

At present, coverage numbers are not required when making checkins (to ensure we don't regress the number) but this may become a requirement in the future.