Testing in Flutter

Sep 19 2023 · Dart 2.19.3, Flutter 3.7.6, Android Studio 2021.3.1, Visual Studio Code 1.7.4

Part 5: Generate Goldens

18. Add Custom Fonts to Goldens

Episode complete

Play next episode

Next
About this episode
Leave a rating/review
See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 17. Widget Test for Multiple Screen Sizes Next episode: 19. Generate Code Coverage Report

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Heads up... You've reached locked video content where the transcript will be shown as obfuscated text.

In this episode, we will use the newly created goldens function to generate goldens. Head over to login_screen_test.dart file and replace the Golden code with the following code.

await doGolden('Login-Page', 'All Widgets on screen', testCaseScreenInfo);
await doGolden('Login-Page', 'Invalid Credentials', testCaseScreenInfo);

await doGolden('Login-Page', 'Valid Credentials', testCaseScreenInfo);

await doGolden('Login-Page', 'Show Loading Indicator', testCaseScreenInfo);

await doGolden('Login-Page', 'Hide Loading Indicator', testCaseScreenInfo);
await doGolden(
 'Quotes-Page', 'Pumped Quotes Page Screen', testCaseScreenInfo);


await doGolden(
 'Quotes-Page', 'Check for circular progress indicator', testCaseScreenInfo);


await doGolden(
     'Quotes-Page', 'Check for mock quotes on screen', testCaseScreenInfo);
 flutter test --update-goldens
  fonts: 
    - family: Roboto
      fonts:
        - asset: fonts/Roboto-Regular.ttf
final roboto = rootBundle.load('fonts/Roboto-Regular.ttf');
final fontLoader = FontLoader('Roboto')..addFont(roboto);

await fontLoader.load();
Future testWidgetsMultipleScreenSizes(
        String testName,
        Future<void> Function(WidgetTester, TestCaseScreenInfo testCase)
            testFunction) async =>
    testCaseScreenInfoList.forEach((testCase) async {
      WidgetController.hitTestWarningShouldBeFatal = true;
      testWidgets("$testName-${testCase.deviceName}", (tester) async {
        final roboto = rootBundle.load('fonts/Roboto-Regular.ttf');
        final fontLoader = FontLoader('Roboto')..addFont(roboto);

        await fontLoader.load();
        await tester.setScreenSize(testCase);
        await testFunction(tester, testCase);
      });
    });
 flutter test --update-goldens