Visualizing Solidity Test Coverage
An easy way to visualize your test coverage on foundry projects is by using the VSCode extension Coverage Gutter.
After you've installed the extension, you can generate a lcov report using the command:
forge coverage --report lcov
This will create a lcov.info
file that will be read by the Coverage Gutter extension.
To enable the coverage visualization, you can click on the Watch button on the bottom left corner of VSCode.
Once you've enabled the Watch mode, in its place you'll start seeing coverage info for the file you have open.
You can also use the keyboard shortcut ⇧⌘P (Shift + Command + P) to pull up the Command Palette on VS Code, and search for Display Coverage. Or you can use the keyboard shortcuts ⇧⌘7(Shift + Command + 7) to display and ⇧⌘7(Shift + Command + 0) to hide the visualization.
Functions that are covered by tests will have a green bar next to them, and the ones that aren't covered by any tests will have a red bar.
After you've added tests, in order for the extension to reflect the changes, you need to re-create the lcov.info
file by using the same command above:
forge coverage --report lcov
Only then, the lines you've written tests for will be marked as covered.