Skip to content

Commit eb62bce

Browse files
authored
Added 'exclude' parameter to 'testWidgets()'. (#86397)
1 parent fd3e03c commit eb62bce

2 files changed

Lines changed: 35 additions & 2 deletions

File tree

‎packages/flutter_test/lib/src/widget_tester.dart‎

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,14 @@ typedef WidgetTesterCallback = Future<void> Function(WidgetTester widgetTester);
100100
/// each value of the [TestVariant.values]. If [variant] is not set, the test
101101
/// will be run once using the base test environment.
102102
///
103+
/// If either [exclude] or [skip] is `true`, then the test will be skipped. The
104+
/// difference is that [skip] is a temporary way to disable a problematic test
105+
/// while a fix is being developed. It should have a comment after it with a
106+
/// link to a tracking issue for the work on re-enabling the test.
107+
///
108+
/// [exclude] is used to indicate that the test is not designed to run under
109+
/// the condition given and should always be skipped when it is `true`.
110+
///
103111
/// If the [tags] are passed, they declare user-defined tags that are implemented by
104112
/// the `test` package.
105113
///
@@ -117,11 +125,26 @@ typedef WidgetTesterCallback = Future<void> Function(WidgetTester widgetTester);
117125
/// expect(find.text('Success'), findsOneWidget);
118126
/// });
119127
/// ```
128+
///
129+
/// ### Excluded test
130+
/// ```dart
131+
/// testWidgets('Some test that will never make sense for the web', (WidgetTester tester) async {
132+
/// // test code
133+
/// }, exclude: isBrowser);
134+
/// ```
135+
///
136+
/// ### Skipped test
137+
/// ```dart
138+
/// testWidgets('Some flaky test', (WidgetTester tester) async {
139+
/// // test code
140+
/// }, skip: true); // https://github.com/flutter/flutter/issues/12345
141+
/// ```
120142
@isTest
121143
void testWidgets(
122144
String description,
123145
WidgetTesterCallback callback, {
124-
bool? skip,
146+
bool skip = false,
147+
bool exclude = false,
125148
test_package.Timeout? timeout,
126149
Duration? initialTimeout,
127150
bool semanticsEnabled = true,
@@ -169,7 +192,7 @@ void testWidgets(
169192
timeout: initialTimeout,
170193
);
171194
},
172-
skip: skip,
195+
skip: (exclude || skip) ? true : null,
173196
timeout: timeout ?? binding.defaultTestTimeout,
174197
tags: tags,
175198
);

‎packages/flutter_test/test/widget_tester_test.dart‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,16 @@ void main() {
738738
});
739739
});
740740

741+
group('Skip and exclude work', () {
742+
testWidgets('skipping a test skips it', (WidgetTester tester) async {
743+
expect(true, false); // shouldn't get here
744+
}, skip: true); // https://github.com/someissue
745+
746+
testWidgets('excluding a test skips it', (WidgetTester tester) async {
747+
expect(true, false); // shouldn't get here
748+
}, exclude: true);
749+
});
750+
741751
group('Pending timer', () {
742752
late TestExceptionReporter currentExceptionReporter;
743753
setUp(() {

0 commit comments

Comments
 (0)