e2e 0.2.0+1

  • Readme
  • Changelog
  • Example
  • Installing
  • new51

e2e #

This package enables self-driving testing of Flutter code on devices and emulators. It can adapt the test results in a format that is compatible with flutter drive and native Android instrumentation testing.

iOS support is not available yet, but is planned in the future.

Usage #

Add a dependency on the e2e package in the dev_dependencies section of pubspec.yaml. For plugins, do this in the pubspec.yaml of the example app.

Invoke E2EWidgetsFlutterBinding.ensureInitialized() at the start of a test file, e.g.

import 'package:e2e/e2e.dart';

void main() {
  testWidgets("failing test example", (WidgetTester tester) async {
    expect(2 + 2, equals(5));
  exit(result == 'pass' ? 0 : 1);

Using Flutter driver to run tests #

E2EWidgetsTestBinding supports launching the on-device tests with flutter drive. Note that the tests don't use the FlutterDriver API, they use testWidgets instead.

Put the a file named <package_name>_test.dart in the app' test_driver directory:

import 'package:flutter_driver/flutter_driver.dart';

Future<void> main() async {
  final FlutterDriver driver = await FlutterDriver.connect();
  await driver.requestData(null, timeout: const Duration(minutes: 1));
  exit(result == 'pass' ? 0 : 1);

To run a example app test with Flutter driver:

cd example
flutter drive test/<package_name>_e2e.dart

To test plugin APIs using Flutter driver:

cd example
flutter drive --driver=test_driver/<package_name>_test.dart test/<package_name>_e2e.dart

Android device testing #

Create an instrumentation test file in your application's android/app/src/androidTest/java/com/example/myapp/ directory (replacing com, example, and myapp with values from your app's package name). You can name this test file MainActivityTest.java or another name of your choice.

package com.example.myapp;

import androidx.test.rule.ActivityTestRule;
import dev.flutter.plugins.e2e.FlutterRunner;
import org.junit.Rule;
import org.junit.runner.RunWith;

public class MainActivityTest {
  public ActivityTestRule<MainActivity> rule = new ActivityTestRule<>(MainActivity.class);

Update your application's myapp/android/app/build.gradle to make sure it uses androidx's version of AndroidJUnitRunner and has androidx libraries as a dependency.

android {
  defaultConfig {
    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

dependencies {
    testImplementation 'junit:junit:4.12'

    // https://developer.android.com/jetpack/androidx/releases/test/#1.2.0
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

To e2e test on a local Android device (emulated or physical):

./gradlew connectedAndroidTest -Ptarget=`pwd`/../test_driver/<package_name>_e2e.dart

Firebase Test Lab #

To run an e2e test on Android devices using Firebase Test Lab, use gradle commands to build an instrumentation test for Android.

pushd android
./gradlew assembleAndroidTest
./gradlew assembleDebug -Ptarget=<path_to_test>.dart

Upload to Firebase Test Lab, making sure to replace <PATH_TO_KEY_FILE>, <PROJECT_NAME>, <RESULTS_BUCKET>, and <RESULTS_DIRECTORY> with your values.

gcloud auth activate-service-account --key-file=<PATH_TO_KEY_FILE>
gcloud --quiet config set project <PROJECT_NAME>
gcloud firebase test android run --type instrumentation \
  --app build/app/outputs/apk/debug/app-debug.apk \
  --test build/app/outputs/apk/androidTest/debug/app-debug-androidTest.apk\
  --timeout 2m \
  --results-bucket=<RESULTS_BUCKET> \

iOS support for Firebase Test Lab is not yet available, but is planned.

0.2.0+1 #

  • Updated README.

0.2.0 #

  • Renamed package from instrumentation_adapter to e2e.
  • Refactored example app test.
  • Breaking change. Renamed InstrumentationAdapterFlutterBinding to E2EWidgetsFlutterBinding.
  • Updated README.

0.1.4 #

  • Migrate example to AndroidX.
  • Define clang module for iOS.

0.1.3 #

  • Added example app.
  • Added stub iOS implementation.
  • Updated README.
  • No longer throws errors when running tests on the host.

0.1.2 #

  • Added support for running tests using Flutter driver.

0.1.1 #

  • Updates about using androidx library.

0.1.0 #

  • Update boilerplate test to use @Rule instead of FlutterTest.

0.0.2 #

  • Document current usage instructions, which require adding a Java test file.

0.0.1 #

  • Initial release


e2e_example #

Demonstrates how to use the e2e plugin.

Getting Started #

This project is a starting point for a Flutter application.

A few resources to get you started if this is your first Flutter project:

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  e2e: ^0.2.0+1

2. Install it

You can install packages from the command line:

with Flutter:

$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:e2e/e2e.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Oct 11, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.1
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.4


Detected platforms: Flutter

References Flutter, and has no conflicting libraries.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
flutter_test 0.0.0
Transitive dependencies
async 2.3.0 2.4.0
boolean_selector 1.0.5
charcode 1.1.2
collection 1.14.11 1.14.12
matcher 0.12.5
meta 1.1.7
path 1.6.4
pedantic 1.8.0+1
quiver 2.0.5
sky_engine 0.0.99
source_span 1.5.5
stack_trace 1.9.3
stream_channel 2.0.0
string_scanner 1.0.5
term_glyph 1.1.0
test_api 0.2.5 0.2.8
typed_data 1.1.6
vector_math 2.0.8