Unverified Commit 3b067049 authored by Katarina Sheremet's avatar Katarina Sheremet Committed by GitHub

Support tags in testWidgets (#55141)

parent 7b1d2421
......@@ -53,3 +53,4 @@ Efthymios Sarpmpanis <e.sarbanis@gmail.com>
Cédric Wyss <cedi.wyss@gmail.com>
Michel Feinstein <michel@feinstein.com.br>
Michael Lee <ckmichael8@gmail.com>
Katarina Sheremet <katarina@sheremet.ch>
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('included', (WidgetTester tester) async {
expect(2 + 2, 4);
}, tags: <String>['include-tag']);
testWidgets('excluded', (WidgetTester tester) async {
throw 'this test should have been filtered out';
}, tags: <String>['exclude-tag']);
}
......@@ -89,6 +89,9 @@ typedef WidgetTesterCallback = Future<void> Function(WidgetTester widgetTester);
/// each value of the [TestVariant.values]. If [variant] is not set, the test
/// will be run once using the base test environment.
///
/// If the [tags] are passed, they declare user-defined tags that are implemented by
/// the `test` package.
///
/// See also:
///
/// * [AutomatedTestWidgetsFlutterBinding.addTime] to learn more about
......@@ -112,6 +115,7 @@ void testWidgets(
Duration initialTimeout,
bool semanticsEnabled = true,
TestVariant<Object> variant = const DefaultTestVariant(),
dynamic tags,
}) {
assert(variant != null);
assert(variant.values.isNotEmpty, 'There must be at least on value to test in the testing variant');
......@@ -150,6 +154,7 @@ void testWidgets(
},
skip: skip,
timeout: timeout ?? binding.defaultTestTimeout,
tags: tags,
);
}
}
......
......@@ -125,6 +125,35 @@ void main() {
expect(result.exitCode, 1);
});
testUsingContext('flutter test should run a widgetTest with a given tag', () async {
Cache.flutterRoot = '../..';
final ProcessResult result = await _runFlutterTest('filtering_tag_widget', automatedTestsDirectory, flutterTestDirectory,
extraArguments: const <String>['--tags', 'include-tag']);
if (!(result.stdout as String).contains('+1: All tests passed')) {
fail('unexpected output from test:\n\n${result.stdout}\n-- end stdout --\n\n');
}
expect(result.exitCode, 0);
});
testUsingContext('flutter test should not run a widgetTest with excluded tag', () async {
Cache.flutterRoot = '../..';
final ProcessResult result = await _runFlutterTest('filtering_tag_widget', automatedTestsDirectory, flutterTestDirectory,
extraArguments: const <String>['--exclude-tags', 'exclude-tag']);
if (!(result.stdout as String).contains('+1: All tests passed')) {
fail('unexpected output from test:\n\n${result.stdout}\n-- end stdout --\n\n');
}
expect(result.exitCode, 0);
});
testUsingContext('flutter test should run all widgetTest when tags are unspecified', () async {
Cache.flutterRoot = '../..';
final ProcessResult result = await _runFlutterTest('filtering_tag_widget', automatedTestsDirectory, flutterTestDirectory);
if (!(result.stdout as String).contains('+1 -1: Some tests failed')) {
fail('unexpected output from test:\n\n${result.stdout}\n-- end stdout --\n\n');
}
expect(result.exitCode, 1);
});
testUsingContext('flutter test should test runs to completion', () async {
Cache.flutterRoot = '../..';
final ProcessResult result = await _runFlutterTest('trivial', automatedTestsDirectory, flutterTestDirectory,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment