Getting Real Code Coverage

It’s not enough just to type flutter test — coverage as it leaves out how to get the actual fancy html metrics report generated. Let me show you an easy to do exactly that for your flutter project.
lcov and You
Lcov on most unix systems computes code coverage on unit tests. While in our Flutter projects we can get the lcov file generated, it seems that Android Studio can not view it.
Let me show you an easy way to generate the HTML report so that you can actually view the report in Android Studio.
Pre-Requirements
You need two things for this to work. First, you install Perl. Those on MS Windows, you can install the strawberry perl distribution of Perl at:
Make sure to add the perl executable to your path settings.
The second requirement is you need Peter Oberparleiter’s(that VaL Doroshchuk ported to windows) perl script to generate the html metrics report which you can find at:
https://raw.githubusercontent.com/valbok/lcov/master/genhtml.perl
In your OS terminal from your flutter project subfolder you will type:
./genhtml.perl ./coverage/lcov.info -o coverage/html
And you will get a nice subfolder called metrics in your flutter project and the generated report looks something like this:

Conclusion
Keep in mind that it’s better combine this report along with the McCabe cycle metrics report on tests that I talk about in my McCabe cycles articles for a full effective code coverage picture.
Resources
Specific article resources:
VaL Doroshchuk’s Port of Peter Oberparleiter’s genthmlPerl script
General Flutter and Dart resources:
Android Studio IDE MS’s Visual Studio Code Flutter Docs Dart Docs Google Firebase Mobile Device TestLab
Trademark Notice
Google LLC owns the following trademarks; Dart, Flutter, Android, Roboto, Noto. Apple Inc owns the trademarks iOS, MacOSX, Swift, and ObjectiveC. Apple Inc owns trademarks to their fonts of SF Pro, Sf Compact, SF mono, and New York. JetBeans Inc owns the trademarks to JetBeans, IntelliJ, and Kotlin. Oracle Inc owns the Java trademark. Microsoft Inc owns the trademarks to MS Windows OS and Powershell. Gradle is a trademark of Gradle Inc. The Git Project owns the trademark to Git. Linux Foundation owns the trademark to Linux. SmartPhone OME’s own trademarks to their mobile phone product names. To the best of my ability I follow the brand and usage guidelines with the above mentioned trademarks.
About Fred Grott
I’m the crazy SOB who as a former android mobile developer is starting to write about flutter mobile app development, design, and life(see Eff COVID and GOP). Will I reach the pivotal One Million Medium monthly viewers mark? Sit-back and watch it happen. Find me on these social platforms:






