Skip to content

Commit ffe94a2

Browse files
authored
Add retry flag to flutter_test (flutter#125851)
Closes flutter#125920 I will add tests, polish code, etc, if this change looks generally OK!
1 parent 7f1f765 commit ffe94a2

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

packages/flutter_test/lib/src/test_compat.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,8 @@ void test(
185185
/// should explain why the group is skipped; this reason will be printed instead
186186
/// of running the group's tests.
187187
@isTestGroup
188-
void group(Object description, void Function() body, { dynamic skip }) {
189-
_declarer.group(description.toString(), body, skip: skip);
188+
void group(Object description, void Function() body, { dynamic skip, int? retry }) {
189+
_declarer.group(description.toString(), body, skip: skip, retry: retry);
190190
}
191191

192192
/// Registers a function to be run before tests.

packages/flutter_test/lib/src/widget_tester.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ void testWidgets(
130130
bool semanticsEnabled = true,
131131
TestVariant<Object?> variant = const DefaultTestVariant(),
132132
dynamic tags,
133+
int? retry,
133134
}) {
134135
assert(variant.values.isNotEmpty, 'There must be at least one value to test in the testing variant.');
135136
final TestWidgetsFlutterBinding binding = TestWidgetsFlutterBinding.ensureInitialized();
@@ -174,6 +175,7 @@ void testWidgets(
174175
skip: skip,
175176
timeout: timeout ?? binding.defaultTestTimeout,
176177
tags: tags,
178+
retry: retry,
177179
);
178180
}
179181
}

packages/flutter_test/test/widget_tester_test.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,24 @@ void main() {
5151
});
5252
});
5353

54+
group('group retry flag allows test to run multiple times', () {
55+
bool retried = false;
56+
group('the group with retry flag', () {
57+
testWidgets('the test inside it', (WidgetTester tester) async {
58+
addTearDown(() => retried = true);
59+
expect(retried, isTrue);
60+
});
61+
}, retry: 1);
62+
});
63+
64+
group('testWidget retry flag allows test to run multiple times', () {
65+
bool retried = false;
66+
testWidgets('the test with retry flag', (WidgetTester tester) async {
67+
addTearDown(() => retried = true);
68+
expect(retried, isTrue);
69+
}, retry: 1);
70+
});
71+
5472
group('respects the group skip flag', () {
5573
testWidgets('should be skipped', (WidgetTester tester) async {
5674
expect(false, true);

0 commit comments

Comments
 (0)