Invalid test coverage report

Steps to Reproduce

A reproduction repository with a minimalistic example is here: https://github.com/rrousselGit/coverage_issue_reproduction

Running flutter test --coverage on that project generates an invalid reporting for the class Foo from lib\src\hook_widget.dart:

image

The dispose method is called by the tests, but for some reasons, the coverage tells that dispose haven’t been called.

Removing the following from test\flutter_test.dart:

class MockState extends Mock implements Foo {}

fixes the coverage issue.

Logs

[√] Flutter (Channel master, v1.1.3-pre.40, on Microsoft Windows [Version 10.0.17134.320], locale en-US)
    • Flutter version 1.1.3-pre.40 at C:\Users\rro3898\dev\flutter
    • Framework revision b8a035a3d4 (11 hours ago), 2018-12-18 20:36:35 -0800
    • Engine revision 08465e8000
    • Dart version 2.2.0 (build 2.2.0-dev.1.1 f9ebf21297)

[√] Android toolchain - develop for Android devices (Android SDK 28.0.3)
    • Android SDK at C:\Users\rro3898\AppData\Local\Android\sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-28, build-tools 28.0.3
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)
    • All Android licenses accepted.

[!] Android Studio (version 3.2)
    • Android Studio at C:\Program Files\Android\Android Studio
    X Flutter plugin not installed; this adds Flutter specific functionality.
    X Dart plugin not installed; this adds Dart specific functionality.
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)

[!] VS Code (version 1.30.0)
    • VS Code at C:\Users\rro3898\AppData\Local\Programs\Microsoft VS Code
    X Flutter extension not installed; install from
      https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[!] Connected device
    ! No devices available

! Doctor found issues in 3 categories.

Author: Fantashit

1 thought on “Invalid test coverage report

  1. Ok. The problem is basically that if you write a class that implements another class, and in the child class you make a noSuchMethod function instead of implementing all of the base class’s methods (which is how mockito works), then you get this extra 0 on the base class’s method:

           |class Foo {
          1|  void
          0|  bar
           |  () {
          1|    print("bar");
           |  }
           |}
           |
           |class Unused implements Foo {
          0|  dynamic noSuchMethod(Invocation invocation) {
          0|    print("noSuchMethod");
           |  }
           |}
           |
          1|void main() {
          2|  Foo().bar();
          1|  print("ok");
           |}
    

Comments are closed.