testExecutable function

Future<void> testExecutable({
  1. required FutureOr<void> testMain(),
  2. required List<TestingTheme> themes,
  3. required WidgetWrapperBuilder wrapper,
  4. required Color backgroundColor(
    1. ThemeData
    ),
  5. required List<TestDevice> devicesForTest,
  6. List<LocalizationsDelegate> localizations = const [],
  7. List<Locale> locales = const [Locale('en')],
  8. double tolerance = 0.18,
  9. LocalFileComparator? customComparator,
})

Entry point for the widget test.

  • testMain - function that contains the actual test.
  • themes - list of themes used for testing.
  • localizations - localization delegates used for testing.
  • locales - list of locales used for testing. If not provided, generate goldens only for english.
  • wrapper - wrapper for the widget test.
  • backgroundColor - background color for the golden file.
  • devicesForTest - list of devices used for testing.
  • customComparator - custom comparator for the golden file.

Implementation

Future<void> testExecutable({
  required FutureOr<void> Function() testMain,
  required List<TestingTheme> themes,
  required WidgetWrapperBuilder wrapper,
  required Color Function(ThemeData) backgroundColor,
  required List<TestDevice> devicesForTest,
  List<LocalizationsDelegate<dynamic>> localizations = const [],
  List<Locale> locales = const [Locale('en')],
  double tolerance = 0.18,
  LocalFileComparator? customComparator,
}) {
  themesForTesting = themes;
  localizationsForTesting = localizations;
  localesForTesting = locales;
  widgetWrapper = wrapper;
  getBackgroundColor = backgroundColor;
  return GoldenToolkit.runWithConfiguration(
    () async {
      await loadAppFonts();
      await testMain();

      if (goldenFileComparator is LocalFileComparator) {
        goldenFileComparator = customComparator ??
            CustomFileComparator(
              '${(goldenFileComparator as LocalFileComparator).basedir}/goldens',
              tolerance,
            );
      }
    },
    config: GoldenToolkitConfiguration(
      defaultDevices: devicesForTest,
      enableRealShadows: true,
    ),
  );
}