Support tags in testWidgets (#55141)
This commit is contained in:
parent
7b1d24216e
commit
3b067049ad
1
AUTHORS
1
AUTHORS
@ -53,3 +53,4 @@ Efthymios Sarpmpanis <e.sarbanis@gmail.com>
|
|||||||
Cédric Wyss <cedi.wyss@gmail.com>
|
Cédric Wyss <cedi.wyss@gmail.com>
|
||||||
Michel Feinstein <michel@feinstein.com.br>
|
Michel Feinstein <michel@feinstein.com.br>
|
||||||
Michael Lee <ckmichael8@gmail.com>
|
Michael Lee <ckmichael8@gmail.com>
|
||||||
|
Katarina Sheremet <katarina@sheremet.ch>
|
||||||
|
@ -0,0 +1,14 @@
|
|||||||
|
// 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
|
/// each value of the [TestVariant.values]. If [variant] is not set, the test
|
||||||
/// will be run once using the base test environment.
|
/// 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:
|
/// See also:
|
||||||
///
|
///
|
||||||
/// * [AutomatedTestWidgetsFlutterBinding.addTime] to learn more about
|
/// * [AutomatedTestWidgetsFlutterBinding.addTime] to learn more about
|
||||||
@ -112,6 +115,7 @@ void testWidgets(
|
|||||||
Duration initialTimeout,
|
Duration initialTimeout,
|
||||||
bool semanticsEnabled = true,
|
bool semanticsEnabled = true,
|
||||||
TestVariant<Object> variant = const DefaultTestVariant(),
|
TestVariant<Object> variant = const DefaultTestVariant(),
|
||||||
|
dynamic tags,
|
||||||
}) {
|
}) {
|
||||||
assert(variant != null);
|
assert(variant != null);
|
||||||
assert(variant.values.isNotEmpty, 'There must be at least on value to test in the testing variant');
|
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,
|
skip: skip,
|
||||||
timeout: timeout ?? binding.defaultTestTimeout,
|
timeout: timeout ?? binding.defaultTestTimeout,
|
||||||
|
tags: tags,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -125,6 +125,35 @@ void main() {
|
|||||||
expect(result.exitCode, 1);
|
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 {
|
testUsingContext('flutter test should test runs to completion', () async {
|
||||||
Cache.flutterRoot = '../..';
|
Cache.flutterRoot = '../..';
|
||||||
final ProcessResult result = await _runFlutterTest('trivial', automatedTestsDirectory, flutterTestDirectory,
|
final ProcessResult result = await _runFlutterTest('trivial', automatedTestsDirectory, flutterTestDirectory,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user