remove_from_coverage 2.0.0 copy "remove_from_coverage: ^2.0.0" to clipboard
remove_from_coverage: ^2.0.0 copied to clipboard

A command-line tool to customize the contents of a coverage file.


Example Project #

Given here is an example project that can use remove_from_coverage to fix its coverage data in coverage/

Project Explanation #

In lib, name.dart contains a Name class that stores a first, middle, and last name. Since we want Name to be an immutable value class, it makes use of the excellent built_value package to automatically generate a toString method, == operator, and builder.

built_value does its code generation in another file, name.g.dart, using Dart's part mechanic to link it to name.dart.

We can trigger the code generation with the following command:

pub run build_runner build

In test, name_test.dart covers the functionality we desire from this package.

The Problem #

Our test in name_test.dart is sufficient for our testing of name.dart, but code coverage packages would also evaluate the coverage of name.g.dart. There might be cases where we'd want to test everything in that generated file, but if we don't, that generated file might have very few lines covered.

Suppose we use the test_cov package to generate coverage statistics:

dart run test_cov

We're told that the code coverage is only 56.9% and the output file is saved to the coverage directory.

The Solution #

We can use remove_from_coverage to strip out undesired data from the file, so that any reports generated from it will properly reflect the coverage.

If pub global scripts are on your path, you can use the following:

remove_from_coverage -f coverage/ -r '.g.dart$'

Otherwise, you can use the following:

dart global run remove_from_coverage:remove_from_coverage -f coverage/ -r '.g.dart$'

Now, shows only the files we desire, so any reports/percentages generates from it will now be correct.

In general, note that generated files should not be added to source control as I've done here. I added name.g.dart and .test_coverage.dart so the example can be browsed online.

Similarly, the entire coverage directory is not often necessary to add to source control.

pub points


unverified uploader

A command-line tool to customize the contents of a coverage file.

Repository (GitHub)
View/report issues


API reference


BSD-3-Clause (LICENSE)




Packages that depend on remove_from_coverage