Skip to content

Measuring test coverage

Hardhat 3 has built-in test coverage functionality to help you identify untested code. It works with Solidity tests by default, and with the hardhat-toolbox-viem plugin, it also works with node:test tests.

Generate a coverage report for your Solidity tests:

Terminal window
npx hardhat test solidity --coverage

The output shows a coverage summary at the end. A Markdown report is printed to the terminal, while LCOV and HTML reports are generated in the coverage folder.

Getting code coverage for TypeScript tests

Section titled “Getting code coverage for TypeScript tests”

Generate a coverage report for your TypeScript tests:

Terminal window
npx hardhat test nodejs --coverage

Get combined coverage for both Solidity and TypeScript tests:

Terminal window
npx hardhat test --coverage