KingWu / gen_lang

gen_lang is a dart library for internationalization. Extracts messages to generate dart files required by Intl, inspired by Intl_translation and Flutter i18n
BSD 2-Clause "Simplified" License
100 stars 23 forks source link

Strings are null at UI tests #17

Open kndl22 opened 4 years ago

kndl22 commented 4 years ago

Hi, I'm building a UI test for my screen - and the test is failing when calling S.of(context).someText

The test:

void main(){
  testWidgets('Intro screen test', (WidgetTester tester) async {
    GetIt.instance.reset();
    locator.registerSingleton(KeyboardManager());

    await tester.pumpWidget(buildTestableWidget(IntroScreen()));
    await tester.pumpAndSettle();

    final buttonFinder = find.byType(IntroCtaButton);

    expect(buttonFinder, findsNWidgets(2));
  });
}

Widget buildTestableWidget(Widget widget) {
  return MediaQuery(
    data: const MediaQueryData(),
    child: MaterialApp(
      localizationsDelegates: const [
        S.delegate,
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate
      ],
      supportedLocales: S.delegate.supportedLocales,
      home: widget,
    ),
  );
}

The error: The getter 'someText' was called on null.

Seen some related issue like this and this medium article but couldn't get it working.

KingWu commented 4 years ago

I tested your setup on my project. Does not face this issue. Can you show flutter doctor?

kndl22 commented 4 years ago

Flutter doctor:

[✓] Flutter (Channel stable, 1.20.2, on Mac OS X 10.15.6 19G73, locale en-IL)
    • Flutter version 1.20.2 at /Users/yuv/Developer/flutter
    • Framework revision bbfbf1770c (3 weeks ago), 2020-08-13 08:33:09 -0700
    • Engine revision 9d5b21729f
    • Dart version 2.9.1

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
    • Android SDK at /Users/yuv/Library/Android/sdk
    • Platform android-29, build-tools 29.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-6222593)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 11.7)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 11.7, Build version 11E801a
    • CocoaPods version 1.9.3

[✓] Android Studio (version 4.0)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 48.1.2
    • Dart plugin version 193.7361
    • Java version OpenJDK Runtime Environment (build
      1.8.0_242-release-1644-b3-6222593)

[✓] Connected device (2 available)
    • Android SDK built for x86 (mobile) • emulator-5554
      • android-x86 • Android 10 (API 29) (emulator)
    • iPhone 11 (mobile)                 • 1811ECB0-2C0F-445B-8226-B2A9A5A0AF50
      • ios         • com.apple.CoreSimulator.SimRuntime.iOS-13-6 (simulator)

• No issues found!
KingWu commented 4 years ago

just upgrade to 1.20.3. And run test case and passed. try to upgrade 1.20.3 and try again?