• About Us
    • Who We Are
    • Our Work
    • Our Clients
    • Our Partners
    • Our Blog
    • News & Events
    • Insights
  • Solutions

    Analytics & Data Management

    Big DataBusiness AnalyticsData IntegrationData Warehousing

    Digital Business Automation

    Advanced Case ManagementBusiness Rules ManagementBusiness Process ManagementRobotic Process Automation

    Connectivity & System Integration

    Agile IntegrationAPI ManagementEnterprise Service Bus

    Enterprise Content Management

    Content Capturing & ImagingEnterprise Content Management

    Enterprise Portal & Mobility

    Digital Customer ExperienceDigital Workplace

  • Services
    • Cloud Apps & Microservices
    • IT Consultancy
    • Application Development
    • Testing Services
  • Careers
    • Careers Homepage
    • Get To Know Us
    • Engineering @ Sumerge
    • Our Culture
    • Benefits & Wellbeing
    • Job Openings
    • Graduate Programs
  • Contact Us
  • About Us
    • Who We Are
    • Our Work
    • Our Clients
    • Our Partners
    • Our Blog
    • News & Events
    • Insights
  • Solutions

    Analytics & Data Management

    Big DataBusiness AnalyticsData IntegrationData Warehousing

    Digital Business Automation

    Advanced Case ManagementBusiness Rules ManagementBusiness Process ManagementRobotic Process Automation

    Connectivity & System Integration

    Agile IntegrationAPI ManagementEnterprise Service Bus

    Enterprise Content Management

    Content Capturing & ImagingEnterprise Content Management

    Enterprise Portal & Mobility

    Digital Customer ExperienceDigital Workplace

  • Services
    • Cloud Apps & Microservices
    • IT Consultancy
    • Application Development
    • Testing Services
  • Careers
    • Careers Homepage
    • Get To Know Us
    • Engineering @ Sumerge
    • Our Culture
    • Benefits & Wellbeing
    • Job Openings
    • Graduate Programs
  • Contact Us
Testing Flutter Apps

Testing Flutter Apps

  • Posted by Yomna Anwar
  • On October 13, 2021

Flutter application testing is a complex process: dozens of screen resolutions, several versions of operating systems, all kinds of connection types, etc. But you just can’t hope for a successful mobile app release without it.

 

Flutter automated testing empowers you to accomplish higher acceptance in your application since it helps you to discover bugs in your application.

 

In this blog, we will explore Integration testing with flutter using flutter drive. We will implement a demo of integration testing for our flutter application and why do we need test cases for our application?

Flutter Testing

The more features your application has the harder it is to test manually. Automated tests help guarantee that your application performs accurately before you publish it.

 

Flutter is an open-source UI software development kit created by Google. It is used to develop cross-platform applications for Android, iOS, Linux, Mac, Windows, Google Fuchsia, and the web from a single codebase.

Flutter Testing Falls into Three Categories:

• Unit Testing.
• Widget Testing.
• Integration Testing

Note: In this blog, we will discuss only Integration Testing.

Why Test Cases?

We write test cases for our applications to verify a particular feature or functionality. A test case contains test steps, test data, precondition, postcondition developed for specific test scenarios to verify any requirement. We try as much as we can to detect the major bugs before publishing them on the store. To ensure that we’ve covered all possible scenarios, we need to start out by creating our test cases.

 

Real device testing helps to guarantee an in-depth analysis of functionality. Testing on real mobile devices always gives precise outcomes for the app and it can totally ensure that a given feature works on an appropriate gadget. It also facilitates a great user experience.

Why Integration Test?

Unit tests and widget tests are handy for testing individual classes, functions, or widgets. However, they generally don’t test how individual pieces work together as a whole or capture the performance of an application running on a real device. These tasks are performed with integration tests.

 

Integration tests work as a pair: first, deploy an instrumented application to a real device or emulator and then “drive” the application from a separate test suite, checking to make sure everything is correct along the way.

 

Note: Instrumentation is a process to prepare the application for testing or automation.

 

To create this test pair, use the “flutter_driver” package. It provides tools to create instrumented apps and drive those apps from a test suite.

Implementation:

Step 1: Create App to test

In this case, we will use MCI BO mobile app as an example app to apply our test.

 

Step 2: Add the dependencies

Add the flutter_driver dependency to pubspec.yaml file.

 

 dev_dependencies:
   flutter_launcher_icons: ^0.7.3
# flutter_test:
# sdk: flutter
 test: any
 flutter_test:
   sdk: flutter
 flutter_driver:
   sdk: flutter

 

Step 3: Create the test files

 

Unlike unit and widget tests, integration test suites do not run in the same process as the app being tested. Therefore, create two files that reside in the “main” project directory. By convention, the directory is named “test_driver”.

 

1. The first file contains an “instrumented” version of the app. The instrumentation allows you to “drive” the app and record performance profiles from a test suite. This file can have any name that makes sense. For this example, create a file called test_driver/app.dart.

 

2. The second file contains the test suite, which drives the app and verifies that it works as expected. The test suite also records performance profiles. The name of the test file must correspond to the name of the file that contains the instrumented app, with _test added at the end. Therefore, create a second file called test_driver/app_test.dart.

 

 

Step 4: Instrument the application

 

1. Enable the flutter driver extensions.
2. Run the app.

 

import 'package:flutter_driver/driver_extension.dart';
void main() async {
  enableFlutterDriverExtension();
  WidgetsFlutterBinding.ensureInitialized();
  if(Device.get().isTablet){
    SystemChrome.setPreferredOrientations([DeviceOrientation.landscapeLeft,DeviceOrientation.landscapeRight]);
  }else{
    SystemChrome.setPreferredOrientations([DeviceOrientation.portraitDown,DeviceOrientation.portraitUp]);
  }

  runApp(MyApp());
}

Step 5: Write the tests

 

Now that you have an instrumented app, you can write tests for it.

 

This involves four steps:

 

1. Create SerializableFinders to locate specific widgets.
2. Connect to the app before our tests run in the setUpAll() function.
3. Test the important scenarios.
4. Disconnect from the app in the teardownAll() function after the tests are complete.

 

 void main() {
  group('MCI Testing', () {
    //login screen
    final usernameTextFinder = find.byValueKey('username');
    final passwordTextFinder = find.byValueKey('password');
    final checkboxFinder = find.byValueKey('rememberMeCheckBox');
    final loginBtnFinder = find.byValueKey('loginButton');
    FlutterDriver driver;
    // Connect to the Flutter driver before running any tests.
    setUpAll(() async {
      driver = await FlutterDriver.connect();
    });

   // Close the connection to the driver after the tests have completed.
   tearDownAll(() async {
     if (driver != null) {
       driver.close();
     }
   });
   test('test login screen', () async {
     //insert username
     await driver.tap(usernameTextFinder);
     await driver.enterText("mawaziny@mci.gov");
    //insert password
     await driver.tap(passwordTextFinder);
     await driver.enterText("P@ssw0rd");
    //check the stay loggedin checkbox
     await driver.tap(checkboxFinder);
   //press login button
     await driver.tap(loginBtnFinder);
     await driver.waitFor(find.text("الرئيسية"));
     await driver.tap(find.text("المدير"));
     await driver.tap(find.text("الرئيسية"));
    });
 });


Step 6: Run the tests

 

To test on iOS or Android, launch an Android Emulator, iOS Simulator, or connect your computer to a real iOS / Android device.

Then, run the following command from the root of the project:

 

flutter drive --target=test_driver/app.dart

This command performs the following:

 

• Builds the –target app and installs it on the emulator/device.
• Launches the app.
• Runs the app_test.dart test suite located in test_driver/ folder.

 
Recent Blog Posts
  • Event Streaming: Enhancing Efficiency in Banking 
  • Your Guide To Integration Modernization
  • APIs: Transforming Chaos into Order
  • Event Streaming Simplified
  • Unlocking the Power of Spring Data JPA
Categories
  • Careers
  • Webinars
  • blog
    • Educational
  • Technology & Business
    • Digital Business Automation
    • /Modernization & Cloud Native Apps
    • Banking
    • Agile Integration
  • Software Engineering
    • Application Servers
    • Application Testing
    • Business Analysis
    • Frontend
    • Microservices
    • Uncategorized
  • Blog Posts
  • News & Events
  • Featured

Remote Onboarding: Tips for an Effective Onboarding Process

Previous thumb

Mutation Testing

Next thumb
Scroll
Follow us

Significant change, positive impact and passion are our fuel. We have a unique culture reflecting the way we think and act. A culture that encourages freedom and responsibility, high performance, customer centricity and innovation.

Global Locations

Egypt

Saudi Arabia

United States

About us

Who We Are
Our Work
Our Clients
Careers
News & Events
Insights

Services

Cloud Apps & Microservices
Application Development
Consultancy
Testing Services

Solutions

Analytics & Data Management
Business Process Automation
Agile Integration
Enterprise Content Management
Enterprise Portal & Mobility

Industries

Banking
Government

Latest Blogs
  • Database Events & Triggers
    December 14, 2022
  • Design Patterns
    August 23, 2022
Copyright Ⓒ 2024 Sumerge. All rights reserved.
  • Blog
  • |
  • Support
  • |
  • Contact Us
  • |
  • Privacy Policy
Sumerge
Manage Cookie Consent
To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Functional Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes. The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
Manage options Manage services Manage {vendor_count} vendors Read more about these purposes
View preferences
{title} {title} {title}

     

    Book A Free Consultation Session

      SumergeLogo Header Menu
      • About Us
        • Who We Are
        • Our Work
        • Our Clients
        • Our Partners
        • Our Blog
        • News & Events
        • Insights
      • Solutions
        • Analytics & Data Management
          • Big Data
          • Business Analytics
          • Data Integration
          • Data Warehousing
        • Digital Business Automation
          • Advanced Case Management
          • Business Process Management
          • Business Rules Management
          • Robotic Process Automation
        • Connectivity & System Integration
          • Agile Integration
          • API Management
          • Enterprise Service Bus
        • Enterprise Content Management
          • Content Capturing & Imaging
          • Enterprise Content Management
        • Enterprise Portal & Mobility
          • Digital Customer Experience
          • Digital Workplace
      • Industry Solutions
        • Banking
          • Digital Banking Transformation
          • Business Process Management
          • Business Rules Management
          • Checks Collection & Clearing
          • Counter Fraud Management
          • Customer Due Diligence
          • Customer Onboarding
          • Daily Vouchers Management
          • Debt Collections & Recovery
          • Enterprise Content Management
          • Enterprise Service Bus
          • Smart Analytics
          • Trade Finance Automation
        • Government
          • Digital Government Transformation
          • Business Analytics
          • Business Process Management
          • Correspondence Management
          • Documents & Records Management
          • Enterprise Service Bus
          • Pensions & Social Programs
          • Social Collaboration Portal
          • Strategy Management
          • Utility Billing
      • Services
        • Cloud Apps & Microservices
        • IT Consultancy
        • Application Development
        • Testing Services
      • Careers
        • Careers Homepage
        • Get To Know Us
        • Engineering @ Sumerge
        • Our Culture
        • Benefits & Wellbeing
        • Job Openings
        • Graduate Programs
      • Contact Us