flutter_test_ui 1.0.0

Flutter Android iOS

Wrapper for flutter_test that adds a tester argument to setUp and tearDown functions

flutter_test_ui #

Wrapper of testWidgets, setUp, and tearDown that provide the WidgetTesterCallback argument to the set-up and tear-down functions: testUI, setUpUI, and tearDownUI.

This allows a single set-up to be shared by several tests and the set-up to be continued in subgroups. In particular, it allows test to be written in rspec style for better readability.

group("testUI and setUpUI example test", () {
  setUpUI((tester) async {
    await tester.pumpWidget(MaterialApp(
      home: Builder(
        builder: (context) => GestureDetector(
          onTap: () => Navigator.of(context).push(
            MaterialPageRoute<void>(
              builder: (context) => Container(
                color: Colors.green,
                child: const Text("page 2"),
              ),
            ),
          ),
          child: Container(
            color: Colors.red,
            child: const Text("page 1"),
          ),
        ),
      ),
    ));
  });

  testUI("first page is shown", (tester) async {
    expect(find.text("page 1"), findsOneWidget);
  });

  group("tapping the text", () {
    setUpUI((tester) async {
      await tester.tap(find.text("page 1"));
      await tester.pumpAndSettle();
    });

    testUI("second page is shown", (tester) async {
      expect(find.text("page 2"), findsOneWidget);
    });

    group("pop the second page", () {
      setUpUI((tester) async {
        final nav = tester.state<NavigatorState>(find.byType(Navigator));
        nav.pop();
        await tester.pumpAndSettle();
      });

      testUI("second page isn't visible anymore", (tester) async {
        expect(find.text("page 2"), findsNothing);
      });

      testUI("first page is visible again", (tester) async {
        expect(find.text("page 1"), findsOneWidget);
      });
    });
  });
});
2
likes
80
pub points
35%
popularity

Wrapper for flutter_test that adds a tester argument to setUp and tearDown functions

Repository (GitHub)
View/report issues

Documentation

API reference

Uploader

spkersten@gmail.com

License

MIT (LICENSE)

Dependencies

flutter, flutter_test, meta

More

Packages that depend on flutter_test_ui