Return to site

Flutter Connect Android Device

broken image


  1. Flutter Android App
  2. Flutter Connect Android Device To Linux

Every pixel in Flutter is drawn with the Skia graphics engine: the same hardware-accelerated engine that powers Android and Chrome. This combination enables fast, glitch-free performance for apps—meaning that apps can operate on a phone's screen at 60 frames per second—which will never feel sluggish, even on a slower device. Testing Flutter Android Apps on Real Devices in Bitbar Cloud. In Bitbar Real Device Cloud, Flutter tests are executed under the Appium Server Side type test project. The ‘run-tests.sh' shell script is used to run the Flutter tests. Integration, Unit and Widget tests can be run in the same project in the cloud. The sample is designed to only show the basics of capturing data in a Flutter app on a Zebra Android device. Many of the DataWedge APIs return values back to the application, for example GETVERSION but none of those APIs are shown in this demo.

Flutter supports both iOS and Android devices/simulators.

In the terminal, run the flutter devices command to verify that Flutter recognizes your connected Android device

Here is a link, How you can setup a device/simulator to run your application.

For, Android (on mac system)

Run your Flutter app on an Android device (you will need an Android device running Android 4.1 (API level 16) or high):

  1. Enable Developer options and USB debugging on your device. Detailed instructions are available in the Android documentation.

  2. Using a USB cable, connect your phone to your computer. If prompted on your device, authorize your computer to access your device.

  3. In the terminal, run the flutter devices command to verify that Flutter recognizes your connected Android device.

  4. Start your app by running flutter run.

By default, Flutter uses the version of the Android SDK where your adb tool is based. If you want Flutter to use a different installation of the Android SDK, you must set the ANDROID_HOME environment variable to that installation directory.

Run your Flutter app on the Android emulator:

  1. Enable VM acceleration on your machine.

  2. Launch Android Studio>Tools>Android>AVD Manager and select Create Virtual Device.

  3. Choose a device definition and select Next.

  4. Select one or more system images for the Android versions you want to emulate, and select Next. An x86 or x86_64 image is recommended.

  5. Under Emulated Performance, select Hardware - GLES 2.0 to enable hardware acceleration.

  6. Verify the AVD configuration is correct, and select Finish.

For details on the above steps, see Managing AVDs.

  1. In Android Virtual Device Manager, click Run in the toolbar. The emulator starts up and displays the default canvas for your selected OS version and device.
  2. Start your app by running a flutter run. The connected device name is Android SDK built for, where the platform is the chip family, such as x86.

Since its initial release, Flutter has quickly gained its popularity among developers for building beautiful Android and iOS applications. Like apps built with any other development toolkit, automated testing of Flutter apps is the only way to ensure app quality in the shortest time possible.

In this article, I'd like to talk about how to create the unit, widget and integration tests for automating the testing of Flutter apps and execute them against real Android devices in Bitbar Cloud.

Creating a Sample Bitbar App with Flutter SDK

To better understand how to automate Flutter app testing, I started creating a Bitbar sample app using Flutter SDK (see UI below).

The MainPage looks like this:

  • Text element
  • 3 button elements (RaisedButton)
  • TextField element
  • Image asset element

The SubPage looks like this:

  • 2 Text elements
  • button element (RaisedButton)
  • TextField element
  • Image asset element

In my opinion, the easiest way to create a new Flutter app is to use the flutter create command, for example: flutter create my_app. This will create a sample app for Android and iOS.

I created the sample app by modifying this sample app. The app source is in a file called main.dart, and it is in the lib directory.

Note: I gave all the important UI elements Key values, for example:

Creating Unit and Widget Tests

A ‘unit test‘ is to test a single method or class and a ‘widget test‘ is to test a single widget. Here, a ‘widget‘ means UI elements like layout, button, text box, etc.

Unit tests require a test package (https://pub.dev/packages/test), and the flutter_test I can t update to macos catalina. package provides additional tools for widget testing.

1. Add the test or flutter_test dependency

Play deuces wild online free. You can use the following approach to include test or flutter_test (or both) dependency on the app's pubspec.yaml file:

2. Create a unit test file

Create a test directory and test file inside that directory. It is also a good idea to make separate directories for unit and widget tests.

In this example, we can create a file ending with _test.dart for example main_test.dart.

Import packages:

Sample test:

3. Create a widget test file

Again create a file ending with _test.dart.

Import packages:

Device

Sample test:

4. Use command to run the tests

Unit tests can be run with the command:

And widget tests can be executed with the command:

5. JUnit Report

One thing to note: If the unit and widget tests are executed in Bitbar Cloud within a CI tool e.g. Jenkins, the test results will not display correctly after the tests are finished.

To get over this, we can use a Flutter package to convert the test results to the JUnit XML report format. (https://pub.dev/packages/junitreport).

First, make sure the following stuff is included in the system path:

  • flutter/.pub-cache/bin
  • flutter/bin/cache/dart-sdk/bin

Then, install the junitreport package by running the command below:

Both unit and widget tests can be run with this command:

After the tests are finished, the unit and widget test results can be found in a file called TEST-all.xml.

Creating Integration Tests

An integration test tests the complete app and is isolated from the app under test. Integration tests require a flutter_driver package (https://api.flutter.dev/flutter/flutter_driver/flutter_driver-library.html).

Flutter driver:

  • The application runs in a separate process from the test itself
  • Android (Espresso)
  • iOS (Earl Grey)
  • Web (Selenium WebDriver)

1. Add the flutter_driver dependency

The flutter_driver package needs to be added to dev_dependencies section of the app's pubspec.yaml file:

2. Create an integration test file

Create a directory called test_driver. Add files main.dart and main_test.dart (or something ending with _test) inside that directory.

Main.dart

This first contains an ‘instrumented' version of the app being tested. It enables Flutter driver extensions and runs the app.

Main_test.dart

This file is created to contain the test suite.

Import Flutter Driver API:

Connect to the app in 'setUpAll' method: Call of duty 4 last level.

Close connection in 'tearDownAll' method:

3. Write a sample integration test:

4. Use command to run the integration tests

Now that we have an instrumented app and a test suite, we can run integration tests with the following command:

There doesn't seem to be a ready package for converting integration test results in a format that could be read in a CI tool, at least at the time of writing this. Test results must be parsed and converted to Junit XML format or something else.

5. Take screenshots

Screenshots can be taken in the integration tests with the ‘screenshots' package (https://pub.dev/packages/screenshots).

Add the dependency in the pubspec.yaml file (the current version of the package at the time of writing this blog):

Create the screenshots.yaml file inside the project root directory. It should look something like this:

Add these in the main_test.dart file:

Import dependency:

Create a config:

Take screenshot inside test method like this:

Testing Flutter Android Apps on Real Devices in Bitbar Cloud

In Bitbar Real Device Cloud, Flutter tests are executed under the Appium Server Side type test project. The ‘run-tests.sh' shell script is used to run the Flutter tests. Integration, Unit and Widget tests can be run in the same project in the cloud.

Note that only integration tests actually install and run the test in a device, unit and widget tests don't require devices to run. Device time is still spent when running unit or widget tests, the device is just idling while the test is running.

See a quick demo below.

Unit and Widget tests

Install JUnit report:

Run unit and widget tests:

Fl producer edition. Move test results to root directory so that they can be found by Jenkins:

Below is the content of the ‘run-tests.sh' file

Integration tests

Flutter Android App

Run tests with the command:

Parse results and convert them into a Junit .xml file called ‘TEST-all.xml' or just look at the log file (console.log) after the test run has ended. Move screenshots to the directory in the root called ‘screenshots':

How to create and start a Flutter test run in Bitbar Cloud

1. Create a zip-file containing app directory (app and tests, in my case ‘my_app' directory) and ‘run-tests.sh' file.

2. Select Android as your target OS type and select the ‘Appium Android Server Side' type as the framework.

3. Upload your test files to the ‘Appium Server Side' type project in Bitbar Cloud.

Gimp latest version free download for windows 7. Note: Since the actual Flutter app to test is written in the ‘flutter-tests.zip' file and will be built during the test run, you could upload any dummy .apk file, e.g. ‘bitbar-sample-app.apk' (see below) to get the test run started on Bitbar Cloud.

4. Start your Flutter test and get the test results

Conclusion

Flutter Connect Android Device To Linux

Testing Flutter apps in Bitbar Cloud is available on real Android devices. Integration test results are not showing correctly without parsing and formatting them yourself. Note that examples in this article have nothing to do with the Appium test automation framework.





broken image