代码之家  ›  专栏  ›  技术社区  ›  xpeldev

颤振:小部件测试中的异常测试

  •  3
  • xpeldev  · 技术社区  · 7 年前

    expect(
      () => tester.tap(find.byIcon(Icons.send)),
      throwsA(const TypeMatcher<UnrecognizedTermException>()),
    );
    

    它失败,出现以下错误

    ...
    Expected: throws <Instance of 'TypeMatcher<UnrecognizedTermException>'>
      Actual: <Closure: () => Future<void>>
       Which: returned a Future that emitted <null>
    

    或者……我应该测试用户界面 查找错误消息等导致的异常??

    1 回复  |  直到 7 年前
        1
  •  5
  •   Jonah Williams    7 年前

    要捕获颤振测试中抛出的异常,请使用 WidgetTester.takeException

    await tester.tap(find.byIcon(Icons.send));
    expect(tester.takeException(), isInstanceOf<UnrecognizedTermException>());
    

    你也不需要一个 throwsA matcher,因为它不是从方法中抛出的。