Added 'exclude' parameter to 'testWidgets()'. (#86397)
diff --git a/packages/flutter_test/lib/src/widget_tester.dart b/packages/flutter_test/lib/src/widget_tester.dart
index 9cbec13..9651fda 100644
--- a/packages/flutter_test/lib/src/widget_tester.dart
+++ b/packages/flutter_test/lib/src/widget_tester.dart
@@ -100,6 +100,14 @@
/// each value of the [TestVariant.values]. If [variant] is not set, the test
/// will be run once using the base test environment.
///
+/// If either [exclude] or [skip] is `true`, then the test will be skipped. The
+/// difference is that [skip] is a temporary way to disable a problematic test
+/// while a fix is being developed. It should have a comment after it with a
+/// link to a tracking issue for the work on re-enabling the test.
+///
+/// [exclude] is used to indicate that the test is not designed to run under
+/// the condition given and should always be skipped when it is `true`.
+///
/// If the [tags] are passed, they declare user-defined tags that are implemented by
/// the `test` package.
///
@@ -117,11 +125,26 @@
/// expect(find.text('Success'), findsOneWidget);
/// });
/// ```
+///
+/// ### Excluded test
+/// ```dart
+/// testWidgets('Some test that will never make sense for the web', (WidgetTester tester) async {
+/// // test code
+/// }, exclude: isBrowser);
+/// ```
+///
+/// ### Skipped test
+/// ```dart
+/// testWidgets('Some flaky test', (WidgetTester tester) async {
+/// // test code
+/// }, skip: true); // https://github.com/flutter/flutter/issues/12345
+/// ```
@isTest
void testWidgets(
String description,
WidgetTesterCallback callback, {
- bool? skip,
+ bool skip = false,
+ bool exclude = false,
test_package.Timeout? timeout,
Duration? initialTimeout,
bool semanticsEnabled = true,
@@ -169,7 +192,7 @@
timeout: initialTimeout,
);
},
- skip: skip,
+ skip: (exclude || skip) ? true : null,
timeout: timeout ?? binding.defaultTestTimeout,
tags: tags,
);
diff --git a/packages/flutter_test/test/widget_tester_test.dart b/packages/flutter_test/test/widget_tester_test.dart
index e3ce327..ebdcd61 100644
--- a/packages/flutter_test/test/widget_tester_test.dart
+++ b/packages/flutter_test/test/widget_tester_test.dart
@@ -738,6 +738,16 @@
});
});
+ group('Skip and exclude work', () {
+ testWidgets('skipping a test skips it', (WidgetTester tester) async {
+ expect(true, false); // shouldn't get here
+ }, skip: true); // https://github.com/someissue
+
+ testWidgets('excluding a test skips it', (WidgetTester tester) async {
+ expect(true, false); // shouldn't get here
+ }, exclude: true);
+ });
+
group('Pending timer', () {
late TestExceptionReporter currentExceptionReporter;
setUp(() {