HELP PLEASE! Flutter tests of Tab Bar

568 views
Skip to first unread message

Federico Mestrone

unread,
Nov 9, 2020, 10:12:37 AM11/9/20
to Flutter Development (flutter-dev)
Hi all,

I have a very simple tab bar

appBar: AppBar(
bottom: TabBar(
tabs: [
Tab(icon: Icon(Icons.toc)),
Tab(icon: Icon(Icons.school)),
Tab(icon: Icon(Icons.connect_without_contact)),
Tab(icon: Icon(Icons.mail_outline)),
],
),
title: Text('MyApp'),
)

and I want to test that each tab opens up the right view. I have tried all sorts but without luck

testWidgets('Click on lesson tab', (WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(MyAppTabHome());

var v = find.byType(Tab).at(1);
await tester.tap(v);
await tester.pump();

expect(find.text('L1'), findsOneWidget);
expect(find.text('L2'), findsOneWidget);
expect(find.text('L3'), findsOneWidget);
expect(find.text('L4'), findsOneWidget);
});

Am I doing it wrong?

Thanks

Fed

Federico Mestrone

unread,
Nov 9, 2020, 10:14:43 AM11/9/20
to Flutter Development (flutter-dev)
I have also tried the following, of course to no avail

var v = find.byIcon(Icons.school);

Suzuki Tomohiro

unread,
Nov 9, 2020, 4:06:07 PM11/9/20
to Federico Mestrone, Flutter Development (flutter-dev)
What's the unexpected?

--
You received this message because you are subscribed to the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/d96e646c-bfe3-43f2-91ed-aa110f62e7a0n%40googlegroups.com.

Federico Mestrone

unread,
Nov 9, 2020, 5:45:39 PM11/9/20
to Flutter Development (flutter-dev)
When I open the second tab, there should be four Text widgets, with "L1" "L2" "L3" "L4" respectively, but the test fails, cannot find the Text widgets

══╡ 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: _TextFinder:<zero widgets with text "L1" (ignoring offstage widgets)>
   Which: means none were found but one was expected


Reply all
Reply to author
Forward
0 new messages