Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Codelab "How to test a Flutter app" Step 6 Widget tests throw exceptions #5190

Closed
crcdng opened this issue Jan 17, 2021 · 19 comments
Closed
Labels
a.tut.codelab-google Relates to codelabs hosted on codelabs.developers.google.com e1-hours Effort: < 8 hrs p2-medium Necessary but not urgent concern. Resolve when possible.

Comments

@crcdng
Copy link

crcdng commented Jan 17, 2021

Following the instructions on the Codelab "How to test a Flutter app" through to Step 6 "Widget Testing"
on page

https://codelabs.developers.google.com/codelabs/flutter-app-testing#5

beginning with 'Testing Scrolling', widget tests throw exceptions (see below) and fail, regardless of platform and regardless if physical device or emulator. 'Testing if ListView shows up' does succeed.

Code is copy / pasted from the codelab.
Note: The unit tests and integration tests from the same codelab work as expected.

I/flutter (15446): (The following exception is now available via WidgetTester.takeException:)
I/flutter (15446): ══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
I/flutter (15446): The following TestFailure object was thrown running a test:
I/flutter (15446):   Expected: no matching nodes in the widget tree
I/flutter (15446):   Actual: _TextFinder:<exactly one widget with text "Item 0" (ignoring offstage widgets):
I/flutter (15446): Text-[<'text_0'>]("Item 0", dependencies: [MediaQuery, DefaultTextStyle])>
I/flutter (15446):    Which: means one was found but none were expected
I/flutter (15446): 
I/flutter (15446): When the exception was thrown, this was the stack:
I/flutter (15446): #4      main.<anonymous closure>.<anonymous closure> (file:///Users/m/root/topics/coding/flutter/learning/testing/test/screens/home_test.dart:21:7)
I/flutter (15446): <asynchronous suspension>
I/flutter (15446): <asynchronous suspension>
I/flutter (15446): (elided one frame from package:stack_trace)
I/flutter (15446): ...
I/flutter (15446): 
I/flutter (15446): This was caught by the test expectation on the following line:
I/flutter (15446):   file:///Users/m/root/topics/coding/flutter/learning/testing/test/screens/home_test.dart line 21
I/flutter (15446): The test description was:
I/flutter (15446):   Testing Scrolling
I/flutter (15446): ════════════════════════════════════════════════════════════════════════════════════════════════════
I/flutter (15446): (If WidgetTester.takeException is called, the above exception will be ignored. If it is not, then the above exception will be dumped when another exception is caught by the framework or when the test ends, whichever happens first, and then the test will fail due to having not caught or expected the exception.)
I/flutter (15446): ══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
I/flutter (15446): The following TestFailure object was thrown running a test:
I/flutter (15446):   Expected: no matching nodes in the widget tree
I/flutter (15446):   Actual: _TextFinder:<exactly one widget with text "Item 0" (ignoring offstage widgets):
I/flutter (15446): Text-[<'text_0'>]("Item 0", dependencies: [MediaQuery, DefaultTextStyle])>
I/flutter (15446):    Which: means one was found but none were expected
I/flutter (15446): 
I/flutter (15446): When the exception was thrown, this was the stack:
I/flutter (15446): #4      main.<anonymous closure>.<anonymous closure> (file:///Users/m/root/topics/coding/flutter/learning/testing/test/screens/home_test.dart:21:7)
I/flutter (15446): <asynchronous suspension>
I/flutter (15446): <asynchronous suspension>
I/flutter (15446): (elided one frame from package:stack_trace)
I/flutter (15446): ...
I/flutter (15446): 
I/flutter (15446): This was caught by the test expectation on the following line:
I/flutter (15446):   file:///Users/m/root/topics/coding/flutter/learning/testing/test/screens/home_test.dart line 21
I/flutter (15446): The test description was:
I/flutter (15446):   Testing Scrolling
I/flutter (15446): ════════════════════════════════════════════════════════════════════════════════════════════════════
I/flutter (15446): 00:02 +0: Home Page Widget Tests Testing Scrolling [E]
I/flutter (15446):   Test failed. See exception logs above.
I/flutter (15446):   The test description was: Testing Scrolling
I/flutter (15446):   
I/flutter (15446): 00:02 +0 -1: Some tests failed.

flutter doctor -v                           
[✓] Flutter (Channel dev, 1.26.0-8.0.pre, on macOS 11.1 20C69 darwin-x64, locale
    en-GB)
    • Flutter version 1.26.0-8.0.pre at /Users/m/root/topics/coding/flutter/sdk
    • Framework revision b9d06fffb2 (9 days ago), 2021-01-07 18:36:48 -0800
    • Engine revision 42a8d4c681
    • Dart version 2.12.0 (build 2.12.0-179.0.dev)

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at /Users/m/Library/Android/sdk
    • Platform android-30, build-tools 30.0.3
    • Java binary at: /Applications/Android
      Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build
      1.8.0_242-release-1644-b3-6915495)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 12.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.3, Build version 12C33
    • CocoaPods version 1.10.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 4.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • 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
      1.8.0_242-release-1644-b3-6915495)

[✓] IntelliJ IDEA Community Edition (version 2020.3.1)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • Flutter plugin version 52.2.5
    • Dart plugin version 203.6912

[✓] VS Code (version 1.52.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.18.1

[✓] Connected device (4 available)
    • G8341 (mobile)              • BH905PQH8Y                               •
      android-arm64  • Android 9 (API 28)
    • sdk gphone x86 arm (mobile) • emulator-5554                            •
      android-x86    • Android 11 (API 30) (emulator)
    • midev1 (mobile)             • a1dc22872978776b04ca280e3a3240adaa3fda50 •
      ios            • iOS 14.3
    • Chrome (web)                • chrome                                   •
      web-javascript • Google Chrome 87.0.4280.141

• No issues found!
@crcdng crcdng changed the title Codelab How to test a Flutter app Step 6 Widget tests throw exceptions Codelab "How to test a Flutter app' Step 6 Widget tests throw exceptions Jan 17, 2021
@crcdng crcdng changed the title Codelab "How to test a Flutter app' Step 6 Widget tests throw exceptions Codelab "How to test a Flutter app" Step 6 Widget tests throw exceptions Jan 17, 2021
@sfshaza2
Copy link
Contributor

sfshaza2 commented Feb 3, 2021

@johnpryan, I see this person is using the dev channel. Could that explain why the test is failing?

@ShortyLago
Copy link

ShortyLago commented Feb 18, 2021

I have the same issue. And the app loaded like this:
Simulator Screen Shot - iPhone 12 Pro Max - 2021-02-18 at 15 12 17

Running pod install...                                           2,980ms
Running Xcode build...                                                  
 └─Compiling, linking and signing...                         4.5s
Xcode build done.                                           25.2s
flutter: 00:00 +0: Home Page Widget Tests Testing if ListView shows up  
flutter: 00:01 +1: Home Page Widget Tests Testing Scrolling             
flutter: (The following exception is now available via WidgetTester.takeException:)
flutter: ══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
flutter: The following TestFailure object was thrown running a test:    
flutter:   Expected: no matching nodes in the widget tree               
flutter:   Actual: _TextFinder:<exactly one widget with text "Item 0" (ignoring offstage widgets):
flutter: Text-[<'text_0'>]("Item 0", dependencies: [MediaQuery, DefaultTextStyle])>
flutter:    Which: means one was found but none were expected           
flutter:                                                                
flutter: When the exception was thrown, this was the stack:             
flutter: #4      main.<anonymous closure>.<anonymous closure> (file:///Users/shorty/StudioProjects/testing_app/test/home_test.dart:26:7)
flutter: <asynchronous suspension>                                      
flutter: <asynchronous suspension>                                      
flutter: (elided one frame from package:stack_trace)                    
flutter: ...                                                            
flutter:                                                                
flutter: This was caught by the test expectation on the following line: 
flutter:   file:///Users/shorty/StudioProjects/testing_app/test/home_test.dart line 26
flutter: The test description was:                                      
flutter:   Testing Scrolling                                            
flutter: ════════════════════════════════════════════════════════════════════════════════════════════════════
flutter: (If WidgetTester.takeException is called, the above exception will be ignored. If it is not, then the above exception will be dumped when another exception is caught by the framework or when the test ends, whichever happens first, and then the test will fail due to having not caught or expected the exception.)
flutter: ══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
flutter: The following TestFailure object was thrown running a test:    
flutter:   Expected: no matching nodes in the widget tree               
flutter:   Actual: _TextFinder:<exactly one widget with text "Item 0" (ignoring offstage widgets):
flutter: Text-[<'text_0'>]("Item 0", dependencies: [MediaQuery, DefaultTextStyle])>
flutter:    Which: means one was found but none were expected           
flutter:                                                                
flutter: When the exception was thrown, this was the stack:             
flutter: #4      main.<anonymous closure>.<anonymous closure> (file:///Users/shorty/StudioProjects/testing_app/test/home_test.dart:26:7)
flutter: <asynchronous suspension>                                      
flutter: <asynchronous suspension>                                      
flutter: (elided one frame from package:stack_trace)                    
flutter: ...                                                            
flutter:                                                                
flutter: This was caught by the test expectation on the following line: 
flutter:   file:///Users/shorty/StudioProjects/testing_app/test/home_test.dart line 26
flutter: The test description was:                                      
flutter:   Testing Scrolling                                            
flutter: ════════════════════════════════════════════════════════════════════════════════════════════════════
flutter: 00:02 +1: Home Page Widget Tests Testing Scrolling [E]         
flutter:   Test failed. See exception logs above.                       
  The test description was: Testing Scrolling
flutter:                                                                
flutter: 00:02 +1 -1: Home Page Widget Tests Testing IconButtons        
flutter: (The following exception is now available via WidgetTester.takeException:)
flutter: ══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
flutter: The following TestFailure object was thrown running a test:    
flutter:   Expected: exactly one matching node in the widget tree       
flutter:   Actual: _TextFinder:<zero widgets with text "Added to favorites." (ignoring offstage widgets)>
flutter:    Which: means none were found but one was expected           
flutter:                                                                
flutter: When the exception was thrown, this was the stack:             
flutter: #4      main.<anonymous closure>.<anonymous closure> (file:///Users/shorty/StudioProjects/testing_app/test/home_test.dart:34:7)
flutter: <asynchronous suspension>                                      
flutter: <asynchronous suspension>                                      
flutter: (elided one frame from package:stack_trace)                    
flutter: ...                                                            
flutter:                                                                
flutter: This was caught by the test expectation on the following line: 
flutter:   file:///Users/shorty/StudioProjects/testing_app/test/home_test.dart line 34
flutter: The test description was:                                      
flutter:   Testing IconButtons                                          
flutter: ════════════════════════════════════════════════════════════════════════════════════════════════════
flutter: (If WidgetTester.takeException is called, the above exception will be ignored. If it is not, then the above exception will be dumped when another exception is caught by the framework or when the test ends, whichever happens first, and then the test will fail due to having not caught or expected the exception.)
flutter: ══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
flutter: The following TestFailure object was thrown running a test:    
flutter:   Expected: exactly one matching node in the widget tree       
flutter:   Actual: _TextFinder:<zero widgets with text "Added to favorites." (ignoring offstage widgets)>
flutter:    Which: means none were found but one was expected           
flutter:                                                                
flutter: When the exception was thrown, this was the stack:             
flutter: #4      main.<anonymous closure>.<anonymous closure> (file:///Users/shorty/StudioProjects/testing_app/test/home_test.dart:34:7)
flutter: <asynchronous suspension>                                      
flutter: <asynchronous suspension>                                      
flutter: (elided one frame from package:stack_trace)                    
flutter: ...                                                            
flutter:                                                                
flutter: This was caught by the test expectation on the following line: 
flutter:   file:///Users/shorty/StudioProjects/testing_app/test/home_test.dart line 34
flutter: The test description was:                                      
flutter:   Testing IconButtons                                          
flutter: ════════════════════════════════════════════════════════════════════════════════════════════════════
flutter: 00:04 +1 -1: Home Page Widget Tests Testing IconButtons [E]    
flutter:   Test failed. See exception logs above.                       
  The test description was: Testing IconButtons
flutter:                                                                
flutter: 00:04 +1 -2: Some tests failed.                                
Activating Dart DevTools...                                        10.0s
Syncing files to device iPhone 12 Pro Max...                       149ms

Flutter run key commands.
r Hot reload. 🔥🔥🔥
R Hot restart.
h Repeat this help message.
d Detach (terminate "flutter run" but leave application running).
c Clear the screen
q Quit (terminate the application on the device).
An Observatory debugger and profiler on iPhone 12 Pro Max is available at: http://127.0.0.1:53691/37b94SgY60o=/

Flutter DevTools, a Flutter debugger and profiler, on iPhone 12 Pro Max is available at: http://127.0.0.1:9100?uri=http%3A%2F%2F127.0.0.1%3A53691%2F37b94SgY60o%3D%2F

Running with unsound null safety
For more information see https://dart.dev/null-safety/unsound-null-safety
Application finished.

I'm using Mac with M1 so BigSur 11.2.1.

[✓] Flutter (Channel beta, 1.26.0-17.6.pre, on macOS 11.2.1 20D74 darwin-arm, locale en-SK)
    • Flutter version 1.26.0-17.6.pre at /Users/shorty/Projects/Flutter/flutter
    • Framework revision a29104a69b (2 days ago), 2021-02-16 09:26:56 -0800
    • Engine revision 21fa8bb99e
    • Dart version 2.12.0 (build 2.12.0-259.12.beta)

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at /Users/shorty/Library/Android/sdk
    • Platform android-30, build-tools 30.0.3
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.4, Build version 12D4e
    • CocoaPods version 1.10.1

[✓] Android Studio
    • Android Studio at /Applications/Android Studio 4.2 Preview.app/Contents
    • 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+10-b944.6916264)

[✓] Android Studio (version 4.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • 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 1.8.0_242-release-1644-b3-6915495)

[✓] Connected device (1 available)
    • iPhone 12 Pro Max (mobile) • 5E167E57-B534-4B8E-8771-3166759D3EA9 • ios • com.apple.CoreSimulator.SimRuntime.iOS-14-4 (simulator)

• No issues found!

@sfshaza2 sfshaza2 added a.tut.codelab-google Relates to codelabs hosted on codelabs.developers.google.com e1-hours Effort: < 8 hrs p2-medium Necessary but not urgent concern. Resolve when possible. labels Mar 11, 2021
@crcdng
Copy link
Author

crcdng commented Mar 14, 2021

@johnpryan, I see this person is using the dev channel. Could that explain why the test is failing?

This is not a dev channel channel issue. The 'Testing Scrolling' test case fails consistently and exceprions are thrown as reported also in Flutter 2.0.2 stable channel and across different physical devices and emulators. The scrolling never takes place.

@crcdng
Copy link
Author

crcdng commented Mar 14, 2021

Some more information. The unit tests and integration tests in the codelab run fine. The widget tests in Step 6 look strange after loading as mentioned above: #5190 (comment)

All widget tests that involve scrolling or tapping consistently fail: 'Testing Scrolling', 'Testing IconButtons', 'Testing Remove Button'
Thests that do not involve interaction with the UI 'Testing if ListView shows up' succeed.

This fails on physical devices both iOS and Android as well as emulators across different versions of the test package ^1.14.4 (as in the codelab) to ^1.16.5 (latest version compatible with Flutter 2.02 stable).

Hope that helps someone to identify and fix.

@reiko-dev
Copy link

Even with your repo "SETP_07" the problem persists, i tried on Beta, Dev and Master channels on the latest versions.
I tried on a Samsumg s8 physical device and on Pixel 3A emulator, and the error is the same.

Error generated:

An Observatory debugger and profiler on SM G950F is available at: http://127.0.0.1:56495/ZPK6zZ6X-_Y=/
I/flutter (28606): 00:00 +0: Home Page Widget Tests Testing if ListView shows up
I/flutter (28606): 00:03 +1: Home Page Widget Tests Testing Scrolling
I/flutter (28606):
I/flutter (28606): Warning: A call to fling() with finder "exactly one widget with type "ListView" (ignoring offstage widgets): ListView(scrollDirection: vertical, primary: using primary controller, AlwaysScrollableScrollPhysics, padding: EdgeInsets(0.0, 16.0, 0.0, 16.0), dependencies: [PrimaryScrollController])" derived an Offset (Offset(400.0, 340.0)) that would not hit test on the specified widget.
I/flutter (28606): Maybe the widget is actually off-screen, or another widget is obscuring it, or the widget cannot receive pointer events.
I/flutter (28606): The finder corresponds to this RenderBox: RenderRepaintBoundary#70412 relayoutBoundary=up1
I/flutter (28606): The hit test result at that offset is: HitTestResult(HitTestEntry#7294d(_LiveTestRenderView#398ad), HitTestEntry#65178())
I/flutter (28606): #0 WidgetController._getElementPoint (package:flutter_test/src/controller.dart:958:25)
I/flutter (28606): #1 WidgetController.getCenter (package:flutter_test/src/controller.dart:841:12)
I/flutter (28606): #2 WidgetController.fling (package:flutter_test/src/controller.dart:377:7)
I/flutter (28606): #3 main.. (file:///C:/src/projects/codelabs/testing_codelab/step_07/test/home_test.dart:28:20)
I/flutter (28606):
I/flutter (28606): #4 testWidgets.. (package:flutter_test/src/widget_tester.dart:155:15)
I/flutter (28606):
I/flutter (28606): #5 TestWidgetsFlutterBinding._runTestBody (package:flutter_test/src/binding.dart:782:5)
I/flutter (28606):
I/flutter (28606): To silence this warning, pass "warnIfMissed: false" to "fling()".
I/flutter (28606): To make this warning fatal, set WidgetController.hitTestWarningShouldBeFatal to true.
I/flutter (28606):
The Flutter DevTools debugger and profiler on SM G950F is available at: http://127.0.0.1:9102?uri=http%3A%2F%2F127.0.0.1%3A56495%2FZPK6zZ6X-_Y%3D%2F
I/flutter (28606): (The following exception is now available via WidgetTester.takeException:)
I/flutter (28606): ══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
I/flutter (28606): The following TestFailure object was thrown running a test:
I/flutter (28606): Expected: no matching nodes in the widget tree
I/flutter (28606): Actual: _TextFinder:<exactly one widget with text "Item 0" (ignoring offstage widgets):
I/flutter (28606): Text-[<'text_0'>]("Item 0", dependencies: [DefaultTextStyle, MediaQuery])>
I/flutter (28606): Which: means one was found but none were expected
I/flutter (28606):
I/flutter (28606): When the exception was thrown, this was the stack:
I/flutter (28606): #4 main.. (file:///C:/src/projects/codelabs/testing_codelab/step_07/test/home_test.dart:30:7)
I/flutter (28606):
I/flutter (28606): #5 testWidgets.. (package:flutter_test/src/widget_tester.dart:155:15)
I/flutter (28606):
I/flutter (28606): #6 TestWidgetsFlutterBinding._runTestBody (package:flutter_test/src/binding.dart:782:5)
I/flutter (28606):
I/flutter (28606):
I/flutter (28606): This was caught by the test expectation on the following line:
I/flutter (28606): file:///C:/src/projects/codelabs/testing_codelab/step_07/test/home_test.dart line 30
I/flutter (28606): The test description was:
I/flutter (28606): Testing Scrolling
I/flutter (28606): ════════════════════════════════════════════════════════════════════════════════════════════════════
I/flutter (28606): (If WidgetTester.takeException is called, the above exception will be ignored. If it is not, then the above exception will be dumped when another exception is caught by the framework or when the test ends, whichever happens first, and then the test will fail due to having not caught or expected the exception.)
I/flutter (28606): ══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
I/flutter (28606): The following TestFailure object was thrown running a test:
I/flutter (28606): Expected: no matching nodes in the widget tree
I/flutter (28606): Actual: _TextFinder:<exactly one widget with text "Item 0" (ignoring offstage widgets):
I/flutter (28606): Text-[<'text_0'>]("Item 0", dependencies: [DefaultTextStyle, MediaQuery])>
I/flutter (28606): Which: means one was found but none were expected
I/flutter (28606):
I/flutter (28606): When the exception was thrown, this was the stack:
I/flutter (28606): #4 main.. (file:///C:/src/projects/codelabs/testing_codelab/step_07/test/home_test.dart:30:7)
I/flutter (28606):
I/flutter (28606): #5 testWidgets.. (package:flutter_test/src/widget_tester.dart:155:15)
I/flutter (28606):
I/flutter (28606): #6 TestWidgetsFlutterBinding._runTestBody (package:flutter_test/src/binding.dart:782:5)
I/flutter (28606):
I/flutter (28606):
I/flutter (28606): This was caught by the test expectation on the following line:
I/flutter (28606): file:///C:/src/projects/codelabs/testing_codelab/step_07/test/home_test.dart line 30
I/flutter (28606): The test description was:
I/flutter (28606): Testing Scrolling
I/flutter (28606): ════════════════════════════════════════════════════════════════════════════════════════════════════
I/flutter (28606): 00:04 +1: Home Page Widget Tests Testing Scrolling [E]
I/flutter (28606): Test failed. See exception logs above.
I/flutter (28606): The test description was: Testing Scrolling
I/flutter (28606):
I/flutter (28606): Consider enabling the flag chain-stack-traces to receive more detailed exceptions.
I/flutter (28606): For example, 'pub run test --chain-stack-traces'.
I/flutter (28606): 00:04 +1 -1: Home Page Widget Tests Testing IconButtons
I/flutter (28606):
I/flutter (28606): Warning: A call to tap() with finder "exactly one widget with icon "IconData(U+0E25C)" (ignoring all but first) (ignoring offstage widgets): Icon(IconData(U+0E25C), dependencies: [Directionality, IconTheme])" derived an Offset (Offset(752.0, 132.0)) that would not hit test on the specified widget.
I/flutter (28606): Maybe the widget is actually off-screen, or another widget is obscuring it, or the widget cannot receive pointer events.
I/flutter (28606): The finder corresponds to this RenderBox: RenderSemanticsAnnotations#eb2bf relayoutBoundary=up1
I/flutter (28606): The hit test result at that offset is: HitTestResult(HitTestEntry#0d05f(_LiveTestRenderView#398ad), HitTestEntry#f7711())
I/flutter (28606): #0 WidgetController._getElementPoint (package:flutter_test/src/controller.dart:958:25)
I/flutter (28606): #1 WidgetController.getCenter (package:flutter_test/src/controller.dart:841:12)
I/flutter (28606): #2 WidgetController.tap (package:flutter_test/src/controller.dart:273:18)
I/flutter (28606): #3 main.. (file:///C:/src/projects/codelabs/testing_codelab/step_07/test/home_test.dart:36:20)
I/flutter (28606):
I/flutter (28606): #4 testWidgets.. (package:flutter_test/src/widget_tester.dart:155:15)
I/flutter (28606):
I/flutter (28606): #5 TestWidgetsFlutterBinding._runTestBody (package:flutter_test/src/binding.dart:782:5)
I/flutter (28606):
I/flutter (28606): To silence this warning, pass "warnIfMissed: false" to "tap()".
I/flutter (28606): To make this warning fatal, set WidgetController.hitTestWarningShouldBeFatal to true.
I/flutter (28606):
I/flutter (28606): (The following exception is now available via WidgetTester.takeException:)
I/flutter (28606): ══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
I/flutter (28606): The following TestFailure object was thrown running a test:
I/flutter (28606): Expected: exactly one matching node in the widget tree
I/flutter (28606): Actual: _TextFinder:<zero widgets with text "Added to favorites." (ignoring offstage widgets)>
I/flutter (28606): Which: means none were found but one was expected
I/flutter (28606):
I/flutter (28606): When the exception was thrown, this was the stack:
I/flutter (28606): #4 main.. (file:///C:/src/projects/codelabs/testing_codelab/step_07/test/home_test.dart:38:7)
I/flutter (28606):
I/flutter (28606): #5 testWidgets.. (package:flutter_test/src/widget_tester.dart:155:15)
I/flutter (28606):
I/flutter (28606): #6 TestWidgetsFlutterBinding._runTestBody (package:flutter_test/src/binding.dart:782:5)
I/flutter (28606):
I/flutter (28606):
I/flutter (28606): This was caught by the test expectation on the following line:
I/flutter (28606): file:///C:/src/projects/codelabs/testing_codelab/step_07/test/home_test.dart line 38
I/flutter (28606): The test description was:
I/flutter (28606): Testing IconButtons
I/flutter (28606): ════════════════════════════════════════════════════════════════════════════════════════════════════
I/flutter (28606): (If WidgetTester.takeException is called, the above exception will be ignored. If it is not, then the above exception will be dumped when another exception is caught by the framework or when the test ends, whichever happens first, and then the test will fail due to having not caught or expected the exception.)
I/flutter (28606): ══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
I/flutter (28606): The following TestFailure object was thrown running a test:
I/flutter (28606): Expected: exactly one matching node in the widget tree
I/flutter (28606): Actual: _TextFinder:<zero widgets with text "Added to favorites." (ignoring offstage widgets)>
I/flutter (28606): Which: means none were found but one was expected
I/flutter (28606):
I/flutter (28606): When the exception was thrown, this was the stack:
I/flutter (28606): #4 main.. (file:///C:/src/projects/codelabs/testing_codelab/step_07/test/home_test.dart:38:7)
I/flutter (28606):
I/flutter (28606): #5 testWidgets.. (package:flutter_test/src/widget_tester.dart:155:15)
I/flutter (28606):
I/flutter (28606): #6 TestWidgetsFlutterBinding._runTestBody (package:flutter_test/src/binding.dart:782:5)
I/flutter (28606):
I/flutter (28606):
I/flutter (28606): This was caught by the test expectation on the following line:
I/flutter (28606): file:///C:/src/projects/codelabs/testing_codelab/step_07/test/home_test.dart line 38
I/flutter (28606): The test description was:
I/flutter (28606): Testing IconButtons
I/flutter (28606): ════════════════════════════════════════════════════════════════════════════════════════════════════
I/flutter (28606): 00:06 +1 -1: Home Page Widget Tests Testing IconButtons [E]
I/flutter (28606): Test failed. See exception logs above.
I/flutter (28606): The test description was: Testing IconButtons
I/flutter (28606):
I/flutter (28606): Consider enabling the flag chain-stack-traces to receive more detailed exceptions.
I/flutter (28606): For example, 'pub run test --chain-stack-traces'.
I/flutter (28606): 00:06 +1 -2: Some tests failed.

Flutter doctor -v: [√] Flutter (Channel master, 2.3.0-17.0.pre.397, on Microsoft Windows [versão 10.0.19042.1052], locale pt-BR) • Flutter version 2.3.0-17.0.pre.397 at C:\src\flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 03034e9e4a (6 hours ago), 2021-06-18 00:14:03 -0700 • Engine revision ced58ef9c1 • Dart version 2.14.0 (build 2.14.0-217.0.dev)

[√] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
• Android SDK at C:\Users\lukas\AppData\Local\Android\sdk
• Platform android-30, build-tools 30.0.2
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
• All Android licenses accepted.

[√] Chrome - develop for the web
• Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop for Windows (Visual Studio Community 2019 16.10.1)
• Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community
• Visual Studio Community 2019 version 16.10.31402.337
• Windows 10 SDK version 10.0.19041.0

[√] Android Studio (version 4.0)
• Android Studio at C:\Program Files\Android\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 1.8.0_242-release-1644-b01)

[√] VS Code (version 1.57.1)
• VS Code at C:\Users\lukas\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.23.0

[√] Connected device (4 available)
• sdk gphone x86 (mobile) • emulator-5554 • android-x86 • Android 11 (API 30) (emulator)
• Windows (desktop) • windows • windows-x64 • Microsoft Windows [versão 10.0.19042.1052]
• Chrome (web) • chrome • web-javascript • Google Chrome 91.0.4472.106
• Edge (web) • edge • web-javascript • Microsoft Edge 91.0.864.48

• No issues found!

@crcdng
Copy link
Author

crcdng commented Jul 6, 2021

@i3games some of it seems to have to do with the particular phone (i'm running this on the ios emulator). For example the early scroll test (scroll, then if Item 0 is found) failed on phones with top notches but worked on ones without. Below that I get more errors and am disinclined to go further with this. But, for what it's worth--

"This fails on physical devices both iOS and Android as well as emulators across different versions of the test package ^1.14.4 (as in the codelab) to ^1.16.5 (latest version compatible with Flutter 2.02 stable)."

The physical devices I tested don't have notches. I haven't seen a case where it doesn't fail, which specific devices did the test pass for you?

@crcdng
Copy link
Author

crcdng commented Jul 6, 2021

It would be helpful if someone from the Flutter team could comment if #5190 (comment) is expected behaviour or if this "weird" rendering of widgets already indicates a bug. Because the warning messages clearly indicate that the fling and tap events are not recognized which appears to make these Widget tests fail (I can see the fling cursor but it is not recognized as an UI event). In Integration tests, Widgets render as expected and scrolling and tapping events work just fine.

@sogaiu
Copy link

sogaiu commented Jul 7, 2021

Is this related? flutter/flutter#82542

@crcdng
Copy link
Author

crcdng commented Jul 7, 2021

Is this related? flutter/flutter#82542

appears related, but the description there reads particular and does not match the scope of the problem. On my side ALL widget tests that interact with UI such as fling and tap throw exceptions on ALL devices - simulators and hardware, Android ad iOS. I have seen similiar bug reports - someone at Flutter would need to connect the dots.

@sogaiu
Copy link

sogaiu commented Jul 7, 2021

Thanks for the explanation.

IIUC, TahaTesser, who answered in flutter/flutter#82542 (comment):

Thanks for the update. I think it is better you can file two separate issued for each platform so we can track cause of the issues and get fix for each platform without using this issue from caoblab, which would be misleading, I am labeling for framework in the mean time. Feel free to tag me in the new issue

is a member of the Flutter team.

It wasn't clear to me whether abd99 filed any related issues as requested.

@crcdng
Copy link
Author

crcdng commented Jul 7, 2021

get fix for each platform

It is not an issue of platform, it is independent of platform, I wrote that a couple of times. The testing documentation on Flutter currently has some errors. On top of that Widget testing is broken in Flutter. There are already issues open, some of them for a long time. I try to help, but opening more separate issues does not cut it. Someone at Flutter needs to look at the full picture and make testing and documentation of testing a priority.

@sogaiu
Copy link

sogaiu commented Jul 9, 2021

Yeah I understand what you are saying.

It's not obvious to me that this discussion is being attended to by flutter folks at the moment (iiuc, there are a lot of issues across the various repositories) so my comments were intended to provide possible leads on either a person to explicitly inform (e.g. TahaTesser) or other places to look for such people.

@johnpryan
Copy link
Contributor

I went through this codelab and I wasn't able to reproduce either error. Attached is a project that contains the files for step 6:

testing_app.zip

If I unzip the project, create the iOS / Android project files, and run the tests, the tests are passing:

unzip testing_app.zip
cd testing_app
flutter create .
rm test/widget_test.dart
flutter test
00:03 +7: All tests passed! 

I tried to reproduce on iOS and Android but the tests are passing for both of those.

@crcdng
Copy link
Author

crcdng commented Jul 12, 2021

[...]
flutter test
[...]

I tried to reproduce on iOS and Android but the tests are passing for both of those.

According to https://codelabs.developers.google.com/codelabs/flutter-app-testing/#5 the widget tests can be 'run in the same way as unit tests' (i.e. with flutter test. In this case these tests pass.) ... 'but using a device or an emulator allows you to watch the test running. It also gives you the ability to use hot restart.'

In the codelab the widget tests are run on the device or emulator, i.e. withflutter run test/home_test.dart. This is where these tests fail as documented above.

@johnpryan
Copy link
Contributor

You're right, flutter run test/home_test.dart fails, thanks for the clarification.

Screen Shot 2021-07-13 at 10 01 40 AM

@goderbauer
Copy link
Member

I posted an initial analysis of what broke this at flutter/flutter#82542 (comment).

@johnpryan Should we de-dup these two bugs? Given my analysis above, this is probably a bug in the framework. Should we therefore close this bug and redirect people to the bug filed in the framework repository?

@johnpryan
Copy link
Contributor

Yeah, I don't think there are any required changes to the codelab. I'll close this issue.

@crcdng
Copy link
Author

crcdng commented Jul 28, 2021

Yeah, I don't think there are any required changes to the codelab. I'll close this issue.

I don't think it is a good idea to close this issue. I recommend to amend the codelab or at least leave the issue open until the underlying issue is fixed. As such the codelab is not working and people going through it will run into the problem.

@domesticmouse
Copy link
Contributor

Hi @i3games, I understand the desire to keep the bug open as a tracking bug, but we don't have a process for closing this bug when flutter/flutter#82542 is fixed. De-duping and forwarding people to the active issue prevents duplication of conversation.

hth, brett

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a.tut.codelab-google Relates to codelabs hosted on codelabs.developers.google.com e1-hours Effort: < 8 hrs p2-medium Necessary but not urgent concern. Resolve when possible.
Projects
None yet
Development

No branches or pull requests

8 participants