Package Exports
- solidity-coverage
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (solidity-coverage) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
solidity-coverage
Code coverage for Solidity testing

- For more details about what this is, how it works and potential limitations, see the accompanying article.
solidity-coverageis in development and its accuracy is unknown. If you find discrepancies between the coverage report and your suite's behavior, please open an issue.solidity-coverageis Solcover
Install
$ npm install --save-dev solidity-coverageUsage notes:
- Coverage runs tests a little more slowly.
- Coverage distorts gas consumption. Tests that check exact gas consumption should be skipped.
- Coverage launches its own in-process ganache server. ganache options via the
providerOptionskey in your.solcover.jsconfig file.
Truffle V5
Add "solidity-coverage" to your plugins array in truffle-config.js
module.exports = {
networks: {...},
plugins: ["solidity-coverage"]
}Run
truffle run coverage [options]Command Options
| Option |
Example |
Description |
|---|---|---|
| file | --file="test/registry/*.js" |
Filename or glob describing a subset of JS tests 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) |
| version | Version info | |
| help | Usage notes |
Config Options
Additional options can be specified in a .solcover.js config file located in
the root directory of your project.
Example:
module.exports = {
skipFiles: ['Routers/EtherRouter.sol']
};| Option |
Type |
Default |
Description |
|---|---|---|---|
| silent | Boolean | false | Suppress logging output |
| client | Object | require("ganache-core") |
Useful if you need a specific ganache version. |
| providerOptions | Object | { } |
ganache-core options |
| skipFiles | Array | ['Migrations.sol'] |
Array of contracts or folders (with paths expressed relative to the contracts directory) that should be skipped when doing instrumentation. |
| istanbulReporter | Array | ['html', 'lcov', 'text'] |
Istanbul coverage reporters |
| mocha | Object | { } |
Mocha options to merge into existing mocha config. grep and invert 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 | |
| onTestsComplete | Function | Hook run after the tests complete, before Istanbul reports are generated. | |
| 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. |
FAQ
Common problems & questions:
- Running out of gas
- Running out of memory (locally and in CI)
- Running out of time (in mocha)
- Running in CI
- Why are asserts and requires highlighted as branch points?
Example reports
- metacoin (Istanbul HTML)
- openzeppelin-solidity (Coveralls)
Contribution Guidelines
Contributions are welcome! If you're opening a PR that adds features please consider writing some unit tests for them. Bugs can be reported in the issues.
Set up the development environment with:
$ git clone https://github.com/sc-forks/solidity-coverage.git
$ yarn