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!
This commit is contained in:
parent
7f1f765521
commit
ffe94a2267
@ -185,8 +185,8 @@ void test(
|
|||||||
/// should explain why the group is skipped; this reason will be printed instead
|
/// should explain why the group is skipped; this reason will be printed instead
|
||||||
/// of running the group's tests.
|
/// of running the group's tests.
|
||||||
@isTestGroup
|
@isTestGroup
|
||||||
void group(Object description, void Function() body, { dynamic skip }) {
|
void group(Object description, void Function() body, { dynamic skip, int? retry }) {
|
||||||
_declarer.group(description.toString(), body, skip: skip);
|
_declarer.group(description.toString(), body, skip: skip, retry: retry);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Registers a function to be run before tests.
|
/// Registers a function to be run before tests.
|
||||||
|
@ -130,6 +130,7 @@ void testWidgets(
|
|||||||
bool semanticsEnabled = true,
|
bool semanticsEnabled = true,
|
||||||
TestVariant<Object?> variant = const DefaultTestVariant(),
|
TestVariant<Object?> variant = const DefaultTestVariant(),
|
||||||
dynamic tags,
|
dynamic tags,
|
||||||
|
int? retry,
|
||||||
}) {
|
}) {
|
||||||
assert(variant.values.isNotEmpty, 'There must be at least one value to test in the testing variant.');
|
assert(variant.values.isNotEmpty, 'There must be at least one value to test in the testing variant.');
|
||||||
final TestWidgetsFlutterBinding binding = TestWidgetsFlutterBinding.ensureInitialized();
|
final TestWidgetsFlutterBinding binding = TestWidgetsFlutterBinding.ensureInitialized();
|
||||||
@ -174,6 +175,7 @@ void testWidgets(
|
|||||||
skip: skip,
|
skip: skip,
|
||||||
timeout: timeout ?? binding.defaultTestTimeout,
|
timeout: timeout ?? binding.defaultTestTimeout,
|
||||||
tags: tags,
|
tags: tags,
|
||||||
|
retry: retry,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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', () {
|
group('respects the group skip flag', () {
|
||||||
testWidgets('should be skipped', (WidgetTester tester) async {
|
testWidgets('should be skipped', (WidgetTester tester) async {
|
||||||
expect(false, true);
|
expect(false, true);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user