Felipe Augusto
Felipe Augusto

Reputation: 8184

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?

Upvotes: 19

Views: 4324

Answers (1)

Alexandr Priezzhev
Alexandr Priezzhev

Reputation: 1513

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

Upvotes: 14

Related Questions