TLDR; in this publication, I assumed that you all know how to write test and testing terminology and methods, no mentions here.
What is LCOV
LCOV is a graphical front-end for GCC’s coverage testing tool gcov. It collects gcov data for multiple source files and creates HTML pages containing the source code annotated with coverage information. It also adds overview pages for easy navigation within the file structure. LCOV supports statement, function, and branch coverage measurement.
brew install lcov
Generating an example app — flutter counter app
example test scripts ./test/widget_test.dart
Objective of lcov
- To see the coverage of the code.
- To deliver the code with quality.
To perform the test with coverage
install test_coverage library in pubspec.yml under dev_dependencies
dev_dependencies: flutter_test: sdk: flutter test_coverage: ^0.4.2
- then run test command with flags
flutter test --coverage
- when test complete it will generate folder ‘coverage” in the project directory, to see the result in visualized, run this commands
genhtml -o coverage coverage/lcov.info # Open in the default browser (mac): open coverage/index.html this is the html report, that generated out looks like.
- now you will get the coverage result, but I want to present in the GitHub repo how do I do that? you should get a badge!!!
To generate badge image
- assume that you are at the root of the project
$ yarn init $ yarn add lcov2badge — more detail here
- what you get is the ./coverage_badge.svg that you can use inside the README.md file, like this.
- the example Github code can be found here!
3lVv0w / test_lcov_bedge
this repo demonstrate how to generate coverage badge form lcov.info for unit testing
A new Flutter project.
This project is a starting point for a Flutter application.
A few resources to get you started if this is your first Flutter project:
For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.
If you have any question/discussion with me, you can contact/ follow me
FB: Krisada Vivek
Follow me Krisada Vivek for a more upcoming tech publication
Top comments (0)