# Solidity Coverage in VS Code with Foundry

By [Devan Non](https://paragraph.com/@devanon) · 2022-06-27

---

![](https://storage.googleapis.com/papyrus_images/e80483ff195d55d7463f560833a14f3c54119273c35a96f6e0fb0aad3d8be8eb.png)

Yeah, I know you’ve probably heard about the hype by now. People are flocking to Foundry and there’s nothing you can do about it. So, strap in, there’s been a new release which brings coverage reporting!

Install / Upgrade Foundry
-------------------------

First, make sure you’re on the latest version of Foundry. If you don’t have it, [get it here](https://getfoundry.sh/).

If you do have it installed already, get the latest version by running:

    $ foundryup
    

View Coverage
-------------

To get a coverage report, it all starts with:

    $ forge coverage
    

By default this will display a summary, which will look like this:

![](https://storage.googleapis.com/papyrus_images/1df1d0d0d5cec4ed638dfac22a0bc2034cefc36d7f4025e5610cc75fadb3a4bc.png)

It’s already quite nice, but you can change the output via the `--report` flag. In order to get the coverage displayed nicely in VS Code, we need to use the [LCOV](https://github.com/linux-test-project/lcov) reporter. So, run:

    $ forge coverage --report lcov
    

You should now have a `lcov.info` file in your project directory. LCOV files can be parsed by many tools / extensions. In the case of VS Code I recommend [Coverage Gutters](https://marketplace.visualstudio.com/items?itemName=ryanluker.vscode-coverage-gutters).

1.  Install the Coverage Gutters extension.
    
2.  Open the file you want to see coverage results for.
    
3.  Open the command palette in VS Code (CMD+SHIFT+P or CTRL+SHIFT+P by default) and type “Display Coverage”, you should see the option “Coverage Gutters: Display Coverage“, select it.
    
4.  Now, your file should be nicely colored line-by-line showing if a line has been hit or not (green for hit, red for missed).
    

![](https://storage.googleapis.com/papyrus_images/00de3af91fcb960fec6a581284f003801cb414faf559093dd583801125a61e30.png)

Obviously, there are some issues present. The constructor is definitely being hit in my tests, but it’s showing as a miss! Coverage in Foundry is still very much a work-in-progress, but it’s great that we have an initial version so we can start setting up our tooling and processes around it. Knowing the Foundry team, this feature will quickly blossom into another example of what the premier Solidity testing framework has to offer.

Example Repos
-------------

*   All the examples in this repo were performed on my [ERC4626Votes repo](https://github.com/devanonon/ERC4626Votes).
    
*   [Onbjerg](https://twitter.com/onbjerg) has a nice [example repo which includes the Codecov GitHub action](https://github.com/onbjerg/forge-coverage-test). He also built the actual coverage feature, so kudos to him!

---

*Originally published on [Devan Non](https://paragraph.com/@devanon/solidity-coverage-in-vs-code-with-foundry)*
