From 8c67781f36ec7f754223fc3e28bc1ff5e5b61a43 Mon Sep 17 00:00:00 2001 From: Mehmet Fidanboylu Date: Tue, 7 Jul 2020 09:14:02 -0700 Subject: [PATCH] Comments around hanging tests via runAsync. (#60136) --- packages/flutter_test/lib/src/binding.dart | 2 +- packages/flutter_test/lib/src/widget_tester.dart | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/flutter_test/lib/src/binding.dart b/packages/flutter_test/lib/src/binding.dart index 5f63366b41..f26b7b65e8 100644 --- a/packages/flutter_test/lib/src/binding.dart +++ b/packages/flutter_test/lib/src/binding.dart @@ -362,7 +362,7 @@ abstract class TestWidgetsFlutterBinding extends BindingBase /// /// If `callback` completes with an error, the error will be caught by the /// Flutter framework and made available via [takeException], and this method - /// will return a future that completes will `null`. + /// will return a future that completes with `null`. /// /// Re-entrant calls to this method are not allowed; callers of this method /// are required to wait for the returned future to complete before calling diff --git a/packages/flutter_test/lib/src/widget_tester.dart b/packages/flutter_test/lib/src/widget_tester.dart index 3b1cfac9dc..a570497802 100644 --- a/packages/flutter_test/lib/src/widget_tester.dart +++ b/packages/flutter_test/lib/src/widget_tester.dart @@ -603,12 +603,24 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker /// /// If [callback] completes with an error, the error will be caught by the /// Flutter framework and made available via [takeException], and this method - /// will return a future that completes will `null`. + /// will return a future that completes with `null`. /// /// Re-entrant calls to this method are not allowed; callers of this method /// are required to wait for the returned future to complete before calling /// this method again. Attempts to do otherwise will result in a /// [TestFailure] error being thrown. + /// + /// If your widget test hangs and you are using [runAsync], chances are your + /// code depends on the result of a task that did not complete. Fake async + /// environment is unable to resolve a future that was created in [runAsync]. + /// If you observe such behavior or flakiness, you have a number of options: + /// + /// * Consider restructuring your code so you do not need [runAsync]. This is + /// the optimal solution as widget tests are designed to run in fake async + /// environment. + /// + /// * Expose a [Future] in your application code that signals the readiness of + /// your widget tree, then await that future inside [callback]. Future runAsync( Future callback(), { Duration additionalTime = const Duration(milliseconds: 1000),