How to view code coverage as html for Flutter in Windows?
Asked Answered
F

3

13

I did flutter test --coverage

A lcov.info was generated under coverage

I want to convert this into html but I don't find a tool for Windows.

On linux, you just do:

sudo apt-get update -qq -y
sudo apt-get install lcov -y

Then you do

genhtml coverage/lcov.info -o coverage/html

I am on Windows and 'genhtml' is not recognized as an internal or external command, operable program or batch file.

Forcemeat answered 4/6, 2020 at 0:13 Comment(0)
F
22

Ok I found it. I will leave the anwser here in case it maybe helpful for anyone.

Actually genhtml is a perl script. If you are have git bash installed, you should have perl already. Try where perl on the cmd and it will show you the path.

For me it was at C:\Program Files\Git\usr\bin\perl.exe

Now create a file called genhtml.perl inside your flutter project root directory. (Make sure to .gitignore it) Then in the file, copy and paste the content this https://raw.githubusercontent.com/valbok/lcov/master/genhtml.perl

Finally open git bash and run $ ./genhtml.perl ./coverage/lcov.info -o coverage/html .

Check You are done html files at coverage/html.

On android studio, select index.html then CTRL+SHIFT+C to copy the file path.

Open Chrome and on the url bar add file:///+CTRL+V. Tap enter. You are done.

PS : Who so ever is facing an error like No common filename prefix found! or some other issue, they can try replacing content of genhtml.perl file from below link.

https://raw.githubusercontent.com/linux-test-project/lcov/master/bin/genhtml

Forcemeat answered 4/6, 2020 at 1:13 Comment(1)
I get this error on Windows when I try to run your suggested command: Can't locate DateTime.pm in @INC (you may need to install the DateTime module) (@INC contains: /usr/lib/perl5/site_perb/perl5/core_perl /usr/share/perl5/core_perl) at ./genhtml.perl line 87. BEGIN failed--compilation aborted at ./genhtml.perl line 87.Felice
S
4

set genhtml variable to where the genthml perl script of lcov located to PATH

for me, it's on

C:\ProgramData\chocolatey\lib\lcov\tools\bin

then run the command genhtml coverage/lcov.info -o coverage/html from git bash instead of terminal

-o is shorthand for --output-file

see this article

Sticktight answered 29/4, 2023 at 1:10 Comment(0)
W
2
  1. choco install lcov
    • genhtml: %programdata%\chocolatey\lib\lcov\tools\bin\genhtml
    • perl.exe: C:\Strawberry\perl\bin\perl.exe
  2. perl.exe myGenhtml.perl MyInput.lcov -o myOutputDirPath

    myGenhtml.perl which is a file you can copy and use directly, or modify some of the parameters inside it.

  3. Open <myOutputDirPath>/index.html to see the result.

Here is a script writing with Powershell that may help you run.

Wanitawanneeickel answered 17/6, 2023 at 8:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.