Testing in Flutter

Sep 19 2023 · Dart 2.19.3, Flutter 3.7.6, Android Studio 2021.3.1, Visual Studio Code 1.7.4

Part 6: Generate Coverage Report

20. Add Test Case for Missed Code

Episode complete

About this episode
Leave a rating/review
See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 19. Generate Code Coverage Report

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

As you can see in the code coverage report, we have missed some code. So let’s add tests for that code.

test('json fromJson test', () {
  final data = jsonDecode(mockQuotes);
  final quote =
      data['quotes'].map((quote) => Quotes.fromJson(quote)).toList();
  expect(quote[0].id, 1);
  expect(quote[0].author, 'Shree');
  expect(quote[0].quote, 'I am best');
});

flutter test --update-goldens --coverage

lcov --capture --directory ./coverage --output-file lcov.info

genhtml ./coverage/lcov.info --output-directory ./coverage/html

cmd /k "flutter test --update-goldens --coverage & perl C:\ProgramData\chocolatey\lib\lcov\tools\bin\lcov -o coverage\lcov.info & perl C:\ProgramData\chocolatey\lib\lcov\tools\bin\genhtml -o coverage\html coverage\lcov.info"
sh coverage_report.sh
coverage_report.bat