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

Overview

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);
      });
    });
  });
});
You might also like...

Adds a side menu in all screens with debug information

Adds a side menu in all screens with debug information

Adds a side menu in all screens with debug information. You can decide which information to show and create new modules to include more information.

Oct 7, 2022

This package adds CustomRefreshIndicator widget that allows you to create whatever indicator you want.

This package adds CustomRefreshIndicator widget that allows you to create whatever indicator you want.

Custom Refresh Indicator A flutter package that allows you to easily create a custom refresh indicator widget. TLDR; ONLINE DEMO! QUICK START CustomRe

Dec 16, 2022

Awesome Flutter Snippets is a collection snippets and shortcuts for commonly used Flutter functions and classes

Awesome Flutter Snippets Awesome Flutter Snippets is a collection of commonly used Flutter classes and methods. It increases your speed of development

Dec 9, 2022

Calculator provides simple and advanced mathematical functions in a beautifully designed app.

Calculator provides simple and advanced mathematical functions in a beautifully designed app.

Hi there, I'm Behruz Hurramov Getting Started $ git clone https://github.com/ariscybertech/aris_calculator.git $ flutter packages get Run the applicat

Jul 7, 2022

Calculator provides simple and advanced mathematical functions in a beautifully designed app.

Calculator provides simple and advanced mathematical functions in a beautifully designed app.

Adv Calculator See LICENSE A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get y

Feb 21, 2022

A flutter package from AsurRaa for widgets and utility functions to support mobile departments here.

A flutter package from AsurRaa for widgets and utility functions to support mobile departments here.

sura_flutter A flutter package from AsurRaa for custom widgets and utility functions. Migrate from 0.2.x to 0.3.x BREAKING CHANGE: remove FutureManage

Nov 15, 2022

A package that exports functions for converting, formatting, and nicening of dates/times in Dart.

Instant A library for manipulating and formatting DateTimes in Dart. Dates and times have never been easier. | DateTime timezone manipulation | Easy f

Jan 22, 2022

flutter chat app with firebase , provider and api with all chat app functions

flutter chat app with firebase , provider and api with all chat app functions

Full Chat Flutter App In this app we use FireBase Services(firestore - storage - auth - cloud messageing ) Dio for api setiing such as sending remote

Dec 14, 2022
will cover the GetX Named Route, GetX Route Transition, GetX Route Result, GetX Route Argument, GetX Route Parameter etc.

getx_playground 1-navigation #2-reactiv A new Fl 3-SimpleStateManagement 4-GetXControllerExample 5- DependencyExample 6-TranslationExample 7-ThemeExam

null 4 Nov 11, 2022
A comprehensive flutter/dart tutorial with setup instructions and learning exercises.

flutter-tutorial A comprehensive flutter/dart tutorial with setup instructions and learning exercises. Setup Folder: https://drive.google.com/drive/u/

Eduardo Piccin 1 Oct 21, 2022
A fast start flutter project to make aps faster and skip setup on every application. I am personally using this structure while creating a new project

Flutter Fast Start A fast start flutter project to make apps faster and skip setup on every application. I am personally using this structure while cr

Okan Demir 2 Dec 15, 2022
This is template toolkit fasten your project setup within a minute. The toolkit is based on MVC+S structure.

BWeird Flutter Toolkit! Hi! From a Weirder Flutter has been great on mobile development and I took this opportunity to make it even greater with templ

Setak Varaman !!!! 6 Aug 22, 2021
Demo app with continuous integration setup for auto across android/iOS app stores

demo_flutter_ci A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started

null 0 Dec 25, 2021
Pre-defined setup to start developing flutter project with stacked architecture.

un_official A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started if t

Aashish Jha 0 Dec 27, 2021
Tabbed sliverlist - A simple flutter plugin to setup sliverlist with TabBar with minimal code.

tabbed_sliverlist A package to simplify initialization of TabBar with ListView builder implemented using sliverappbar and sliverlist. Scroll position

Akshay A S 1 Jan 3, 2022
This project demonstarates UI setup for some basic flutter widgets.

Flutter Widgets This project demonstarates UI setup for some basic flutter widgets. Container | | Text | | Button | | Textfield | | Column | | Row | |

Girisankar G 2 Nov 20, 2021
Fluro is a Flutter routing library that adds flexible routing options like wildcards, named parameters and clear route definitions.

English | Português The brightest, hippest, coolest router for Flutter. Features Simple route navigation Function handlers (map to a function instead

Luke Pighetti 3.5k Jan 4, 2023
A list component that refreshes and adds more data for Flutter.

Language: English | 中文简体 Dynamic List View A list component that can refreshes and adds more data for Flutter App. ?? github Installation Add this to

Sword 18 Sep 27, 2022