This was originally a Github Issue in the Dart-Code repository.
I've been working on a package that has hundreds of tests, so an easy way of visualizing code coverage would be incredibly handy.
I would like to run my tests with, say, a .vscode
configuration with an lcov.info
output which would automatically be recognized by VS Code and highlighted on the respective editors with either red or green.
I've tried many different solutions in the past few days — months actually — but none of them worked as the ideal one described above:
flutter test --coverage --coverage-path=lcov.info
does work to generate the necessary file, but it's clunky to have to visualize it through a 3rd party program such as genhtml
, all the more if you're on Windows.
test_coverage
package.
coverage
and the test_coverage
packages offer something close to what I described above, but their solutions are way clunkier — and on Windows they are tough to set up...You can take the genhtml.perl
script here.
If you have Git for Windows installed on your machine, you already have Perl installed, it should be here: <git-install-dir>\usr\bin\perl.exe
Replace backslash characters (\\
) with slash characters (/
) in all file path lines (prefixed with SF:
) in the lcov.info
file.
Run genhtml.perl
script. For example — assumed current working directory is root directory of your project —:
<git-install-dir>\usr\bin\perl.exe \
C:\Scripts\genhtml.perl \
-o .\coverage\html .\coverage\lcov.info
Note. It may be useful also to add the --prefix
option.
As a result of these actions, you should get generated HTML report in the .\coverage\html/
directory. Open .\coverage\html\index.html
file in your browser to see the report.
I hope this helps — at least, it worked for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With