Skip to content

Testing localized widgets can fail when assets are too big due to race condition #22193

@hyochan

Description

@hyochan

Fix: #22193 (comment)


I've found a LINK with exact same question but didn't help.

Could you write some examples of testing localized widgets?
Below is what I've tried.

  testWidgets('Sample Widget', (WidgetTester tester) async {
    // Create the Widget tell the tester to build it
    await tester.pumpWidget(Localizations(
      delegates: [
        const LocalizationDelegate(),
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate
      ],
      locale: Locale('en'),
      child: Sample(sample: 'test'),
    ));
    await tester.pumpAndSettle();

    expect(find.text('test'), findsOneWidget);
    expect(find.text('1'), findsNothing);

    // Tap the '+' icon and trigger a frame.
//    await tester.tap(find.byIcon(Icons.add));
//    await tester.pump();
  });

Result

➜ dooboo git:(master) ✗ flutter test test/widgets/sample.dart
00:07 +0: Sample Widget                                                                                                                            
locale: en
languageCode: en
══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
The following TestFailure object was thrown running a test:
  Expected: exactly one matching node in the widget tree
  Actual: ?:<zero widgets with text "test" (ignoring offstage widgets)>
   Which: means none were found but one was expected

When the exception was thrown, this was the stack:
#4      main.<anonymous closure> (file:///Users/hyochan/Documents/SourceCode/FlutterProjects/dooboo/test/widgets/sample.dart:29:5)
<asynchronous suspension>
#5      testWidgets.<anonymous closure>.<anonymous closure> (package:flutter_test/src/widget_tester.dart:72:23)
#6      TestWidgetsFlutterBinding._runTestBody (package:flutter_test/src/binding.dart:559:19)
<asynchronous suspension>
#9      TestWidgetsFlutterBinding._runTest (package:flutter_test/src/binding.dart:543:14)
#10     AutomatedTestWidgetsFlutterBinding.runTest.<anonymous closure> (package:flutter_test/src/binding.dart:887:24)
#16     AutomatedTestWidgetsFlutterBinding.runTest (package:flutter_test/src/binding.dart:884:15)
#17     testWidgets.<anonymous closure> (package:flutter_test/src/widget_tester.dart:71:22)

flutter doctor

[✓] Flutter (Channel beta, v0.7.3, on Mac OS X 10.14 18A384a, locale en-KR)
[!] Android toolchain - develop for Android devices (Android SDK 27.0.3)
    ! Some Android licenses not accepted.  To resolve this, run: flutter doctor --android-licenses
[!] iOS toolchain - develop for iOS devices (Xcode 10.0)
    ✗ ios-deploy not installed. To install:
        brew install ios-deploy
[✓] Android Studio (version 3.1)
[!] VS Code (version 1.27.2)
[✓] Connected devices (1 available)

! Doctor found issues in 3 categories.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projecta: internationalizationSupporting other languages or locales. (aka i18n)a: tests"flutter test", flutter_test, or one of our testsc: crashStack traces logged to the consoled: api docsIssues with https://api.flutter.dev/f: material designflutter/packages/flutter/material repository.found in release: 3.3Found to occur in 3.3found in release: 3.7Found to occur in 3.7frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onteam-designOwned by Design Languages teamtriaged-designTriaged by Design Languages teamworkaround availableThere is a workaround available to overcome the issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions