Comments around hanging tests via runAsync. (#60136)

This commit is contained in:
Mehmet Fidanboylu 2020-07-07 09:14:02 -07:00 committed by GitHub
parent cfc0082db7
commit 8c67781f36
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 2 deletions

View File

@ -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

View File

@ -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<T> runAsync<T>(
Future<T> callback(), {
Duration additionalTime = const Duration(milliseconds: 1000),