avatarFred Grott

Summary

The website content provides a guide on generating a detailed HTML code coverage report for Flutter projects using lcov and a perl script, which is particularly useful for viewing the report in Android Studio.

Abstract

The article titled "Getting Real Code Coverage" explains the process of obtaining a comprehensive HTML metrics report for Flutter unit tests, which goes beyond the basic coverage provided by flutter test. It outlines the use of lcov to calculate code coverage and addresses the limitation of Android Studio's inability to view the generated lcov file directly. The solution involves installing Perl and using a specific perl script by VaL Doroshchuk, which is a port of Peter Oberparleiter's original script, to convert the lcov data into an HTML report. The author guides readers through the pre-requisites, including installing Strawberry Perl on Windows and adding it to the system path, and provides the necessary commands to generate the report. The article concludes by emphasizing the importance of combining this report with McCabe cycle metrics for a complete understanding of code coverage and references additional resources and trademark notices.

Opinions

  • The author suggests that merely running flutter test — coverage is insufficient for a detailed analysis of code coverage.
  • Viewing the code coverage report within Android Studio is preferable, indicating a need for an HTML-based report.
  • The author provides a subjective assessment that generating the HTML report is "easy," suggesting user-friendliness in the process they describe.
  • The article implies that combining code coverage reports with McCabe cycle metrics reports offers a more robust evaluation of the test suite's effectiveness.
  • The author expresses a personal commitment to writing about Flutter development, design, and life, and sets a goal to reach a significant readership milestone.
  • The inclusion of a trademark notice indicates the author's attention to detail and respect for intellectual property rights.

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:

StrawberryPerl for Windows

VaL Doroshchuk’s Port of Peter Oberparleiter’s genthmlPerl script

General Flutter and Dart resources:

Flutter Community Resources

Flutter SDK

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:

https://twitter.com/fredgrott

Flutter
Code Review
iOS
Android
DevOps
Recommended from ReadMedium