fix #19175 How should addTime be used from a test? (#25202)

This commit is contained in:
TruongSinh Tran-Nguyen
2019-03-07 06:32:33 +07:00
committed by Michael Goderbauer
parent ec27e04582
commit 0c7fe40e37
3 changed files with 53 additions and 67 deletions

View File

@@ -125,6 +125,11 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
@protected
bool get disableShadows => false;
/// Increase the timeout for the current test by the given duration.
void addTime(Duration duration) {
// Noop, see [AutomatedTestWidgetsFlutterBinding. addTime] for an actual implementation.
}
/// The value to set [debugCheckIntrinsicSizes] to while tests are running.
///
/// This can be used to enable additional checks. For example,
@@ -843,7 +848,7 @@ class AutomatedTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
_timeoutCompleter.completeError(
TimeoutException(
'The test exceeded the timeout. It may have hung.\n'
'Consider using "addTime" to increase the timeout before expensive operations.',
'Consider using "tester.binding.addTime" to increase the timeout before expensive operations.',
_timeout,
),
);
@@ -873,6 +878,7 @@ class AutomatedTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
///
/// * [defaultTestTimeout], the maximum that the timeout can reach.
/// (That timeout is implemented by the test package.)
@override
void addTime(Duration duration) {
assert(_timeout != null, 'addTime can only be called during a test.');
_timeout += duration;

View File

@@ -49,6 +49,14 @@ typedef WidgetTesterCallback = Future<void> Function(WidgetTester widgetTester);
///
/// The callback can be asynchronous (using `async`/`await` or
/// using explicit [Future]s).
/// Tests using the [AutomatedTestWidgetsFlutterBinding]
/// have a default time out of two seconds,
/// which is automatically increased for some expensive operations,
/// and can also be manually increased by calling
/// [AutomatedTestWidgetsFlutterBinding.addTime].
/// The maximum that this timeout can reach (automatically or manually increased)
/// is defined by the timeout property,
/// which defaults to [TestWidgetsFlutterBinding.defaultTestTimeout].
///
/// This function uses the [test] function in the test package to
/// register the given callback as a test. The callback, when run,
@@ -56,6 +64,11 @@ typedef WidgetTesterCallback = Future<void> Function(WidgetTester widgetTester);
/// provides convenient widget [Finder]s for use with the
/// [WidgetTester].
///
/// See also:
///
/// * [AutomatedTestWidgetsFlutterBinding.addTime] to learn more about
/// timeout and how to manually increase timeouts.
///
/// ## Sample code
///
/// ```dart