我在尝试测试 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