gen_lang icon indicating copy to clipboard operation
gen_lang copied to clipboard

Strings are null at UI tests

Open kndl22 opened this issue 3 years ago • 3 comments

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.

kndl22 avatar Sep 01 '20 12:09 kndl22

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

KingWu avatar Sep 02 '20 08:09 KingWu

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!

kndl22 avatar Sep 02 '20 09:09 kndl22

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

KingWu avatar Sep 03 '20 10:09 KingWu