From ffe94a2267b4643afcbb40f68d018da4e60ed2e4 Mon Sep 17 00:00:00 2001 From: fzyzcjy <5236035+fzyzcjy@users.noreply.github.com> Date: Fri, 2 Jun 2023 06:25:52 +0800 Subject: [PATCH] Add retry flag to flutter_test (#125851) Closes https://github.com/flutter/flutter/issues/125920 I will add tests, polish code, etc, if this change looks generally OK! --- packages/flutter_test/lib/src/test_compat.dart | 4 ++-- .../flutter_test/lib/src/widget_tester.dart | 2 ++ .../flutter_test/test/widget_tester_test.dart | 18 ++++++++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/packages/flutter_test/lib/src/test_compat.dart b/packages/flutter_test/lib/src/test_compat.dart index bbf7506653..433f586cb3 100644 --- a/packages/flutter_test/lib/src/test_compat.dart +++ b/packages/flutter_test/lib/src/test_compat.dart @@ -185,8 +185,8 @@ void test( /// should explain why the group is skipped; this reason will be printed instead /// of running the group's tests. @isTestGroup -void group(Object description, void Function() body, { dynamic skip }) { - _declarer.group(description.toString(), body, skip: skip); +void group(Object description, void Function() body, { dynamic skip, int? retry }) { + _declarer.group(description.toString(), body, skip: skip, retry: retry); } /// Registers a function to be run before tests. diff --git a/packages/flutter_test/lib/src/widget_tester.dart b/packages/flutter_test/lib/src/widget_tester.dart index 6e6d7ab132..ce8b9ced27 100644 --- a/packages/flutter_test/lib/src/widget_tester.dart +++ b/packages/flutter_test/lib/src/widget_tester.dart @@ -130,6 +130,7 @@ void testWidgets( bool semanticsEnabled = true, TestVariant variant = const DefaultTestVariant(), dynamic tags, + int? retry, }) { assert(variant.values.isNotEmpty, 'There must be at least one value to test in the testing variant.'); final TestWidgetsFlutterBinding binding = TestWidgetsFlutterBinding.ensureInitialized(); @@ -174,6 +175,7 @@ void testWidgets( skip: skip, timeout: timeout ?? binding.defaultTestTimeout, tags: tags, + retry: retry, ); } } diff --git a/packages/flutter_test/test/widget_tester_test.dart b/packages/flutter_test/test/widget_tester_test.dart index 153aed0bc2..a168619b2e 100644 --- a/packages/flutter_test/test/widget_tester_test.dart +++ b/packages/flutter_test/test/widget_tester_test.dart @@ -51,6 +51,24 @@ void main() { }); }); + group('group retry flag allows test to run multiple times', () { + bool retried = false; + group('the group with retry flag', () { + testWidgets('the test inside it', (WidgetTester tester) async { + addTearDown(() => retried = true); + expect(retried, isTrue); + }); + }, retry: 1); + }); + + group('testWidget retry flag allows test to run multiple times', () { + bool retried = false; + testWidgets('the test with retry flag', (WidgetTester tester) async { + addTearDown(() => retried = true); + expect(retried, isTrue); + }, retry: 1); + }); + group('respects the group skip flag', () { testWidgets('should be skipped', (WidgetTester tester) async { expect(false, true);