What's the reason for "async" in testWidgets methods?
167
You need it whenever you use pumpWidgets
, which you pretty much always use if you're using testWidgets
, since that's the point of testWidgets
.
pumpWidgets
uses it because that's how the feature that you can run a test using either flutter test
in accelerated artificial time or flutter run
in real time is implemented.
Author by
Reagankm
Updated on December 01, 2022Comments
-
Reagankm over 1 year
Every example I can find of widget testing has you write methods with a signature
testWidgets('name of the test', (WidgetTester tester) async
. Is theasync
part always necessary by some requirement of the test framework or only if you're using anawait
or making a Future call somewhere in the method body? -
Günter Zöchbauer about 7 years@FrankHarper what part do you think is incorrect? The docs do contain methods where
async
was added even thoughawait
isn't used - for examplesetUp()
. -
Günter Zöchbauer about 7 years@FrankHarper My answer says that
async
is necessary whenawait
is used. Ian just explained why they useawait
in almost every test. Ifawait
is not used,async
is not necessary. Therefore it's not a requirement of the test framework or similar.