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.

Share:
167
Reagankm
Author by

Reagankm

Updated on December 01, 2022

Comments

  • Reagankm
    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 the async part always necessary by some requirement of the test framework or only if you're using an await or making a Future call somewhere in the method body?

  • Günter Zöchbauer
    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 though await isn't used - for example setUp().
  • Günter Zöchbauer
    Günter Zöchbauer about 7 years
    @FrankHarper My answer says that async is necessary when await is used. Ian just explained why they use await in almost every test. If await is not used, async is not necessary. Therefore it's not a requirement of the test framework or similar.