Need help with solidity-coverage?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

432 Stars 149 Forks MIT License 853 Commits 38 Opened issues


Code coverage for Solidity smart-contracts

Services available


Need anything else?

Contributors list


Gitter chat npm (tag) CircleCI codecov buidler

Code coverage for Solidity testing

coverage example


$ npm install --save-dev solidity-coverage

Resources: + 0.7.0 release notes + A guide to upgrading from 0.6.x to 0.7.x + 0.6.3 docs

Truffle V5

Add this package to your plugins array in

(Truffle docs)
module.exports = {
  networks: {...},
  plugins: ["solidity-coverage"]
truffle run coverage [command-options]


Beginning with v0.7.12, this tool supports Hardhat and runs directly on HardhatEVM.

Require the plugin in

(Hardhat docs)


npx hardhat coverage [command-options]

(Additional Hardhat-specific info can be found here)

Buidler [Deprecated]

Add the plugin in

(Buidler docs) ```javascript usePlugin('solidity-coverage')

module.exports = { networks: { coverage: { url: 'http://localhost:8555' } }, }

npx buidler coverage --network coverage [command-options] ```

Buidler Project Examples:


OpenZeppelin have written their own coverage generation scripts for

using the solidity-coverage API. A working example can be found at openzeppelin-contracts, here.

Usage notes:

  • Coverage runs tests a little more slowly.
  • Coverage launches its own in-process ganache server.
  • You can set ganache options using the
    key in your
  • Coverage distorts gas consumption. Tests that check exact gas consumption should be skipped.
  • :warning: Contracts are compiled without optimization. Please report unexpected compilation faults to issue 417

Command Options

| Option | Example | Description | |--------------|------------------------------------|--------------------------------| | file |

| (Truffle) Filename or glob describing a subset of tests to run. (Globs must be enclosed by quotes.)| | testfiles |
--testfiles "test/registry/*.ts"
| (Buidler) Test file(s) to run. (Globs must be enclosed by quotes.)| | solcoverjs |
--solcoverjs ./../.solcover.js
| Relative path from working directory to config. Useful for monorepo packages that share settings. (Path must be "./" prefixed) | | network |
--network development
| Use network settings defined in the Truffle or Buidler config | | temp* |
--temp build
| :warning: Caution :warning: Path to a disposable folder to store compilation artifacts in. Useful when your test setup scripts include hard-coded paths to a build directory. More... |

* Advanced use

Config Options

Additional options can be specified in a

config file located in the root directory of your project.


module.exports = {
  skipFiles: ['Routers/EtherRouter.sol']

| Option | Type | Default | Description | | ------ | ---- | ------- | ----------- | | silent | Boolean | false | Suppress logging output | | client | Object |

| Useful if you need a specific ganache version. | | providerOptions | Object |
{ }
| ganache-core options | | skipFiles | Array |
| Array of contracts or folders (with paths expressed relative to the
directory) that should be skipped when doing instrumentation. | | measureStatementCoverage | boolean |
| Computes statement (in addition to line) coverage. More... | | measureFunctionCoverage | boolean |
| Computes function coverage. More... | | istanbulFolder | String |
| Folder location for Istanbul coverage reports. | | istanbulReporter | Array |
['html', 'lcov', 'text', 'json']
| Istanbul coverage reporters | | mocha | Object |
{ }
| Mocha options to merge into existing mocha config.
are useful for skipping certain tests under coverage using tags in the test descriptions.| | onServerReady* | Function | | Hook run after server is launched, before the tests execute. Useful if you need to use the Oraclize bridge or have setup scripts which rely on the server's availability. More... | | onCompileComplete* | Function | | Hook run after compilation completes, before tests are run. Useful if you have secondary compilation steps or need to modify built artifacts. More...| | onTestsComplete* | Function | | Hook run after the tests complete, before Istanbul reports are generated. More...| | onIstanbulComplete* | Function | | Hook run after the Istanbul reports are generated, before the ganache server is shut down. Useful if you need to clean resources up. More...|

* Advanced use


Solidity-coverage's core methods and many utilities are available as an API.

const CoverageAPI = require('solidity-coverage/api');

Documentation available here.


Common problems & questions:

Example reports

Contribution Guidelines

Contributions are welcome! If you're opening a PR that adds features or options please consider writing full unit tests for them. (We've built simple fixtures for almost everything and are happy to add some for your case if necessary).

Set up the development environment with:

$ git clone
$ yarn


We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.