flutter - Flutter:如何 Widget 测试 使用 Widget 测试共享包
问题描述
我在尝试测试Share包时遇到问题。我的代码如下所示:
IconButton(
key: Key('share-button'),
icon: Icon(Platform.isAndroid ? Icons.share : CupertinoIcons.share),
onPressed: () {
if (activity.shareLink != null) {
Share.share('${activity.shareLink}');
} else {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Request Error'),
),
);
}
},
)
我提供了 [activity.shareLink],我的测试如下所示:
await tester.tap(find.byKey(Key('share-button')));
await tester.pump(Duration(seconds: 1));
expect(find.byType(Share), findsOneWidget);
我的例外是:
══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
The following TestFailure object was thrown running a test:
Expected: exactly one matching node in the widget tree
Actual: _WidgetTypeFinder:<zero widgets with type "Share" (ignoring offstage widgets)>
Which: means none were found but one was expected
解决方案
推荐阅读
- mongodb - 在mongodb的聚合管道中展开操作后查找阶段不起作用
- javascript - json 中的 .push() 导致替换而不是将数组添加到我的 json 变量
- c# - 在 Windows 窗体列表框控件中的最后一项下方创建底部边距
- c++ - c ++ assgin成员变量通过构造函数没有“新”说明符成本调用复制方法?
- swift - 如何显示任何项目?
- mongodb - 在查询中访问 MongoDB 子文档字段(Typescript 和 Mongoose)
- rest - 更正 REST API 语义以检查电子邮件是否存在
- wordpress - WordPress 安装在 Google Cloud Kubernetes 集群上的位置
- python - 在没有循环的情况下查找二维数组中匹配行的索引(一次)
- docker - Dockerfile 中的 apt 和 apt-get 返回错误