Gary Ghayrat's Blog

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.

-----BEGIN PGP PUBLIC KEY BLOCK-----

mDMEZ+KfWhYJKwYBBAHaRw8BAQdAnvwafnga88iMkDLdLTHzrduGaJbadD8CdG8q
EvHq/Ny0EmdhcnkuZ2hheXJhdEBwbS5tZYiWBBMWCAA+FiEEBMx0KkXWrYZP7Vak
eBPgIzXvywMFAmfin1oCGwMFCQPCZwAFCwkIBwIGFQoJCAsCBBYCAwECHgECF4AA
CgkQeBPgIzXvywN7fAEAqy3JU1Fgu/m2r86tapbuNHxK/BjDh/RTkSB7x/oSNdAA
/17MQRn2Zax4LplPunZYeSUv8QsIxxGCAIoJOrARKwoDuDgEZ+KfWhIKKwYBBAGX
VQEFAQEHQGk2Lx6jlW1+PgA6+Ea2+CEBTAdT53RgUdNkws1UaNB5AwEIB4h4BBgW
CAAgFiEEBMx0KkXWrYZP7VakeBPgIzXvywMFAmfin1oCGwwACgkQeBPgIzXvywOi
FwEA4WkQQTBAmNyK8Qph6e7aKfVOEEbyY9epgLNy+nqdCJIA/iG0kjUF+hRDTStU
TTT8nBSAewp4eYvukSWZ8pXlod4F
=oNhV
-----END PGP PUBLIC KEY BLOCK-----

Enter your email to subscribe to updates.