test_coverage 0.4.1

  • Readme
  • Changelog
  • Installing
  • 87

test_coverage Build Status Pub Coverage #

A simple command-line tool to collect test coverage information from Dart VM tests. It is useful if you need to generate coverage reports locally during development.

Usage #

Add dev dependency to your pubspec.yaml:

  test_coverage: ^0.4.1

Run pub get to install. Then, in the root of your project run:

pub run test_coverage

Result is saved in coverage/lcov.info. If you have lcov tool installed on your system (for Mac it's brew install lcov) you can generate coverage reports using genhtml command:

genhtml -o coverage coverage/lcov.info
# Open in the default browser (mac):
open coverage/index.html

Integrations #

Resulting coverage/lcov.info file is ready to be consumed by Codecov command-line tool, so no extra step is needed.

This library was not tested with coveralls yet.

Generating badge image #


Coverage badge SVG image is automatically generated and saved to coverage_badge.svg in your project root directory. You can add it to Git and use in README.md on Github as follows:


If you don't need it you can pass --no-badge flag when running test coverage.

Known limitations #

  • This library was created to run Dart VM tests. It has not been tested and likely won't work for Dart code targeting web platform (compiled to JavaScript). There is no need to use this tool for Flutter as it allows collecting coverage information with flutter test --coverage.

How it works #

The tool performs following steps:

1. Generates test/.test_coverage.dart file (a "test all" script). #

Scans your test/ directory to find all *_test.dart files and creates test/.test_coverage.dart which imports all found test files and runs corresponding main() of all tests functions within the same file (and process), which simplifies collection of coverage information.

It is recommended to add this file to your .gitignore.

Below is an example of test/.test_coverage.dart:

// Auto-generated by test_coverage. Do not edit by hand.
// Consider adding this file to your .gitignore.

import 'some_test.dart' as some_test;
import 'nested/other_test.dart' as other_test;
import 'some_other_test.dart' as some_other_test;

void main() {

2. Runs the tests #

Following command is used to run the tests:

dart --pause-isolates-on-exit --enable_asserts --enable-vm-service \

3. Collects and formats coverage information #

When test execution is completed the tool uses functionality of the coverage package to collect and format coverage report.

Feel free to file feature requests and bug reports at the issue tracker.

0.4.1 #

  • Fixed test generator for windows platform (#11)

0.4.0 #

  • Upgraded to coverage 0.13.0 (#8)

0.3.0 #

  • Refactor code for Dart 2.0 features.
  • Added --exclude, --port, --help and --[no-]badge options. See pub run test_coverage -h for more details.
  • Coverage badge moved from coverage/badge.svg to coverage_badge.svg (in the package root) which makes it easier to manage coverage/ in .gitignore, allows you to commit the badge to your repo and include it in the README.md.

0.2.4 #

  • Upgraded dependencies.
  • Bumped SDK constraint to 2.3.0.

0.2.3 #

  • Prepare for Dart 2 stable.

0.2.2 #

  • Renamed coverage/coverage.lcov to coverage/lcov.info.

0.2.1 #

  • Generate coverage badge in coverage/badge.svg.

0.2.0 #

  • Moved generated reports to coverage/ subfolder.
  • Added tests.
  • Updated usage instructions to recommend local dev_dependencies and pub run test_coverage instead of global installation.

0.1.1 #

  • Make paths in lcov file relative to the project root.

0.1.0 #

  • Initial version

Use this package as an executable

1. Install it

You can install the package from the command line:

$ pub global activate test_coverage

2. Use it

The package has the following executables:

$ test_coverage

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  test_coverage: ^0.4.1

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:test_coverage/test_coverage.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Jun 5, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.2
  • pana: 0.13.8-dev

Health issues and suggestions

Document public APIs. (-1 points)

11 out of 11 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Maintenance issues and suggestions

Support latest dependencies. (-20 points)

The version constraint in pubspec.yaml does not support the latest published versions for 2 dependencies (coverage, lcov).

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

Common filename patterns include main.dart, example.dart, and test_coverage.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.3.0 <3.0.0
args ^1.5.1 1.6.0
coverage ^0.13.0 0.13.11 0.14.0
glob ^1.1.7 1.2.0
lcov ^5.3.0 5.7.0 6.0.0
path ^1.6.1 1.7.0
Transitive dependencies
async 2.4.1
charcode 1.1.3
collection 1.14.12
js 0.6.1+1
json_annotation 3.0.1
logging 0.11.4
meta 1.1.8
node_interop 1.1.1
node_io 1.1.1
package_config 1.9.3
source_maps 0.10.9
source_span 1.7.0
stack_trace 1.9.3
string_scanner 1.0.5
term_glyph 1.1.0
vm_service 4.0.4
Dev dependencies
pedantic ^1.7.0 1.9.0
test ^1.0.0