TestAsyncUtils class abstract final

Utility class for all the async APIs in the flutter_test library.

This class provides checking for asynchronous APIs, allowing the library to verify that all the asynchronous APIs are properly awaited before calling another.

For example, it prevents this kind of code:

tester.pump(); // forgot to call "await"!

...by detecting, in the second call to pump, that it should actually be:

await tester.pump();
await tester.pump();

It does this while still allowing nested calls, e.g. so that you can call expect from inside callbacks.

You can use this in your own test functions, if you have some asynchronous functions that must be used with "await". Wrap the contents of the function in a call to TestAsyncUtils.guard(), as follows:

Future<void> myTestFunction() => TestAsyncUtils.guard(() async {
  // ...




hashCode int
The hash code for this object.
runtimeType Type
A representation of the runtime type of the object.


noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
toString() String
A string representation of this object.


operator ==(Object other) bool
The equality operator.

Static Methods

guard<T>(Future<T> body()) Future<T>
Calls the given callback in a new async scope. The callback argument is the asynchronous body of the calling method. The calling method is said to be "guarded". Nested calls to guarded methods from within the body of this one are fine, but calls to other guarded methods from outside the body of this one before this one has finished will throw an exception.
guardSync() → void
Verifies that there are no guarded methods currently pending (see guard).
verifyAllScopesClosed() → void
Verifies that there are no guarded methods currently pending (see guard).