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

17. Widget Test for Multiple Screen Sizes

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: 16. Widget Extension Functions Next episode: 18. Add Custom Fonts to Goldens

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.

Before we begin, let’s create a new helper function that will help us create goldens in a better way. If you see, Goldens require a name for the screenshot. We will create a new function that will take the widget’s name and generate the golden name for us.

String getGoldenName(
        String page, String state, TestCaseScreenInfo testCaseScreenInfo) =>
    'goldens/$page-$state-${testCaseScreenInfo.deviceName}.png';
Future doGoldenGeneric<T>(
        String page, String state, TestCaseScreenInfo testCaseScreenInfo) =>
    expectLater(find.byType(T),
        matchesGoldenFile(getGoldenName(page, state, testCaseScreenInfo)));
Future doGolden(
        String page, String state, TestCaseScreenInfo? testCaseScreenInfo) =>
    testCaseScreenInfo != null
        ? doGoldenGeneric<MaterialApp>(page, state, testCaseScreenInfo)
        : Future.value();
testWidgetsMultipleScreenSizes('Login-Page', loginWidgetTest);
Future<void> loginWidgetTest(
    WidgetTester tester, TestCaseScreenInfo? testCaseScreenInfo) async {
}
testWidgetsMultipleScreenSizes('All Quotes Widget Test', allQuotesWidgetTest);
Future<void> allQuotesWidgetTest(
  WidgetTester tester, TestCaseScreenInfo? testCaseScreenInfo) async {}
void main() {
  IntegrationTestWidgetsFlutterBinding.ensureInitialized();
  group('Integration Tests', () {
    WidgetController.hitTestWarningShouldBeFatal = true;

    testWidgets('Login-Page', (tester) => loginWidgetTest(tester, null));

    testWidgets('All-Quotes-Page', (tester) => allQuotesWidgetTest(tester, null));
  });
}