Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I generate test coverage of untested files on my flutter tests?

I'm making Widget and Unit testing on my app, I make the tests normally, according to the basic guides, and to generate the coverage I use:

flutter test --coverage

However I just can see the coverage of the files directly tested, I'd like to see the other files (with 0% of coverage), then I could check the real coverage of my code.

Is there a way for doing that?

like image 404
Felipe Augusto Avatar asked Feb 09 '19 03:02

Felipe Augusto


1 Answers

I have created a small helper script to help with the full coverage report generation. It scans your lib directory for *.dart files (excluding *.g.dart) and imports them into the generated test/coverage_test.dart file. Having this generated file coverage analyser will go through the whole project next time you run it. To use the script:

  1. Clone it to any location

    wget https://raw.githubusercontent.com/priezz/dart_full_coverage/master/dart-coverage-helper
    
  2. Make it executable

    chmod +x dart-coverage-helper
    
  3. Ensure that the location of the script is in your PATH environment variable (or just put it into the root of your project).

  4. Run from the root of your Dart/Flutter project

    dart-coverage-helper
    

Then generate the coverage report as usual

flutter test --coverage # for Flutter project
# or
pub run test_coverage   # for Dart project
like image 172
Alexandr Priezzhev Avatar answered Oct 24 '22 23:10

Alexandr Priezzhev