flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
166.71k stars 27.62k forks source link

Text not rendered in snapshot test #41773

Open vanlooverenkoen opened 5 years ago

vanlooverenkoen commented 5 years ago

I am having problems with snapshot testing. My text is not rendered. When I run the app itself everything works perfectly.

void main() {
   testWidgets('Test an account Overview Item', (tester) async {
    await tester.pumpWidget(TestWrapper());

    await tester.pumpAndSettle();

    await expectLater(
      find.byType(RepaintBoundary),
      matchesGoldenFile('account_overview_item_default2.png'),
    );
  });
}

import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:app/util/locale/localization.dart';
import 'package:app/util/locale/localization_delegate.dart';
import 'package:app/util/locale/localization_fallback_cupertino_delegate.dart';

class TestWrapper extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    const locale = Locale('en');
    return Localizations(
      locale: locale,
      delegates: [
        LocalizationDelegate(newLocale: locale),
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
        FallbackCupertinoLocalisationsDelegate.delegate,
      ],
      child: RepaintBoundary(child: LayoutBuilder(builder: (context, constraints) => Text(Localization.of(context).welcomeMessage))),
    );
  }
}

image

[✓] Flutter (Channel stable, v1.9.1+hotfix.2, on Mac OS X 10.15 19A536g, locale en-BE)
    • Flutter version 1.9.1+hotfix.2 at /Users/vanlooverenkoen/flutter
    • Framework revision 2d2a1ffec9 (4 weeks ago), 2019-09-06 18:39:49 -0700
    • Engine revision b863200c37
    • Dart version 2.5.0

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.1)
    • Android SDK at /Users/vanlooverenkoen/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-29, build-tools 29.0.1
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 11.0)
    • Xcode at /Applications/Xcode-beta.app/Contents/Developer
    • Xcode 11.0, Build version 11M382q
    • CocoaPods version 1.7.5

[✓] Android Studio (version 3.5)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 39.0.3
    • Dart plugin version 191.8423
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)

[!] VS Code (version 1.38.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    ✗ Flutter extension not installed; install from
      https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[✓] Connected device (1 available)
    • iPhone Xs Max • 227BD263-CF94-4580-99FC-2C8A9CABBBDD • ios • com.apple.CoreSimulator.SimRuntime.iOS-13-0 (simulator)
escamoteur commented 5 years ago

Hi, thanks for reporting. I guess it's worth to upgrade your current Flutter installation because your version is a bit behind. Possibly a switch to dev or master might help, I found some commit messages in the newer version.

vanlooverenkoen commented 5 years ago

I am on the latest stable release. I will not be using a master, dev version to build production apps.

Zazo032 commented 5 years ago

Probably not to build production apps, but you could try using master branch and see if it's already solved there.

escamoteur commented 5 years ago

@vanlooverenkoen I can completely understand this. It was just a proposal to see if this issue is already fixed. Btw you are not on the latest stable, latest stable is `+hotfix.4.

I'm really sorry I can't tell you more at the moment. The Flutter team will have a look at it as soon as possible.

vanlooverenkoen commented 5 years ago

I will test is right now. strange flutter does not indicates for a new version. Normaly it does

vanlooverenkoen commented 5 years ago

Latest version gives the same result

jason-simmons commented 5 years ago

Flutter tests use the Ahem test font. With this font every character is rendered as a rectangle in order to produce consistent results on all platforms.

escamoteur commented 5 years ago

@jason-simmons so this is expected behavior here? Because you can't see separate rectangles in the screen shot above.

jason-simmons commented 5 years ago

Try changing the color of the text and verifying that the rectangles are rendered with that color.

vanlooverenkoen commented 5 years ago

Yes that is the case

escamoteur commented 5 years ago

OK so it seems to me that everything is working as supposed. Isn't it?

escamoteur commented 5 years ago

But as @jason-simmons explained for the test it does work with real fonts.

vanlooverenkoen commented 5 years ago

Not sure if this is documented somewhere, but it definitely should be.

escamoteur commented 5 years ago

Yeah I agree so I reopen it and add a documentation label

vanlooverenkoen commented 5 years ago

The ability to change font should be documented as well

pedromassango commented 3 months ago

The ability to change font should be documented as well

Have you found a workaround? I am using a custom font for my IconData and tests aren't unable to load them so it is simply rendering squares