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!
First, make sure you’re on the latest version of Foundry. If you don’t have it, get it here.
If you do have it installed already, get the latest version by running:
$ foundryup
To get a coverage report, it all starts with:
$ forge coverage
By default this will display a summary, which will look like this:
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 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.
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.