Skip to content

"flutter test --platform chrome" does not output the same information as "flutter test" when test fails for not awaiting pump calls #107099

@r-durao-pvotal

Description

@r-durao-pvotal

When running tests with flutter test --platform chrome, if a test fails, I want to get as much information as possible in order to fix my test.

flutter test --platform chrome should have the same output as flutter test

Steps to Reproduce

  1. Write the following test and run it with flutter test and flutter test --platform chrome
testWidgets('sampleTest', (tester) async {
  tester.pumpWidget(SizedBox());
  expect(find.byType(SizedBox), findsOneWidget);
});
  1. Observe output from both commands

Output from flutter test

The following assertion was thrown running a test:
Guarded function conflict.
You must use "await" with all Future-returning test APIs.
The guarded method "pumpWidget" from class WidgetTester was called from
file:///home/projects/sample/test/widgets/ui/widgets//widget_test.dart
on line 59.
Then, the "expect" function was called from
file:///home/projects/sample/test/widgets/ui/widgets/widget_test.dart
on line 60.
The first method (WidgetTester.pumpWidget) had not yet finished executing at the time that the
second function (expect) was called. Since both are guarded, and the second was not a nested call
inside the first, the first must complete its execution before the second can be called. Typically,
this is achieved by putting an "await" statement in front of the call to the first.
If you are confident that all test APIs are being called using "await", and this expect() call is
not being called at the top level but is itself being called from some sort of callback registered
before the pumpWidget method was called, then consider using expectSync() instead.

Output from flutter test --platform chrome

The following assertion was thrown running a test:
Assertion failed:
file:///home/flutter/3.0.1-stable/packages/flutter_test/lib/src/test_async_utils.dart:311:14
lineMatch != null
is not true

This is far less descriptive and unless I dig into the source code, I won't be able to understand what is going on. And even then I may not be able to understand why the test is failing.

Expected results: output from flutter test --platform chrome should be the same as flutter test's output

Actual results: output from flutter test --platform chrome is not helpful at all for understanding why a test fails under described scenario

Code sample
import 'package:flutter_test/flutter_test.dart';

void main(){
    testWidgets('sampleTest', (tester) async {
      tester.pumpWidget(SizedBox());
      expect(find.byType(SizedBox), findsOneWidget);
    });
}
Details
ricardo@pt-RD-9570:~/$ flutter doctor -v
[✓] Flutter (Channel stable, 3.0.1, on Ubuntu 20.04.4 LTS 5.13.0-51-generic, locale en_US.UTF-8)
    • Flutter version 3.0.1 at /home/ricardo/.pvotal/flutter/3.0.1-stable
    • Upstream repository ssh://[email protected]/flutter/flutter.git
    • Framework revision fb57da5f94 (7 weeks ago), 2022-05-19 15:50:29 -0700
    • Engine revision caaafc5604
    • Dart version 2.17.1
    • DevTools version 2.12.2

[!] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at /home/ricardo/Android/Sdk
    ✗ cmdline-tools component is missing
      Run `path/to/sdkmanager --install "cmdline-tools;latest"`
      See https://developer.android.com/studio/command-line for more details.
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/linux#android-setup for more details.

[✓] Chrome - develop for the web
    • Chrome at google-chrome

[✓] Linux toolchain - develop for Linux desktop
    • clang version 10.0.0-4ubuntu1
    • cmake version 3.16.3
    • ninja version 1.10.0
    • pkg-config version 0.29.1

[✓] Android Studio (version 4.2)
    • Android Studio at /usr/local/android-studio/android-studio
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.8+0-b944-P17168821)

[✓] VS Code
    • VS Code at /snap/code/current
    • Flutter extension version 3.44.0

[✓] Connected device (2 available)
    • Linux (desktop) • linux  • linux-x64      • Ubuntu 20.04.4 LTS 5.13.0-51-generic
    • Chrome (web)    • chrome • web-javascript • Google Chrome 102.0.5005.61

[✓] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 1 category.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projecta: tests"flutter test", flutter_test, or one of our testsfound in release: 3.0Found to occur in 3.0found in release: 3.1Found to occur in 3.1has reproducible stepsThe issue has been confirmed reproducible and is ready to work onteam-webOwned by Web platform teamtoolAffects the "flutter" command-line tool. See also t: labels.triaged-webTriaged by Web platform team

    Type

    No type

    Projects

    Status

    Future bugs/improvements

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions