Bidev
BeginnerTesting

How do you measure test coverage in a Flutter project?

Short Answer

Run flutter test --coverage to generate a lcov.info file, then use a tool like genhtml (from lcov) or an editor extension to turn it into a readable report showing exactly which lines are covered.

flutter test --coverage runs your whole test suite and outputs coverage/lcov.info in the standard lcov format, which most CI coverage tools (Codecov, Coveralls) and local viewers understand natively. To view it as an HTML report locally: genhtml coverage/lcov.info -o coverage/html, then open coverage/html/index.html.

Coverage percentage is a useful signal but not a goal in itself — 100% line coverage doesn't guarantee correctness, so it's best used to find obviously-untested code paths rather than as a strict quality gate.

Common Mistakes

  • ×Treating a high coverage percentage as proof of correctness rather than just 'this code executed during some test.'
  • ×Not excluding generated files (*.g.dart, *.freezed.dart) from coverage reports, which skews the percentage misleadingly low.