e2e 0.2.2+3

  • Readme
  • Changelog
  • Example
  • Installing
  • 98

e2e #

This package enables self-driving testing of Flutter code on devices and emulators. It adapts flutter_test results into 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() {
  E2EWidgetsFlutterBinding.ensureInitialized();
  testWidgets("failing test example", (WidgetTester tester) async {
    expect(2 + 2, equals(5));
  });
  exit(result == 'pass' ? 0 : 1);
}

Test locations #

It is recommended to put e2e tests in the test/ folder of the app or package. For example apps, if the e2e test references example app code, it should go in example/test/. It is also acceptable to put e2e tests in test_driver/ folder so that they're alongside the runner app (see below).

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>_e2e_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));
  await driver.close();
  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;

@RunWith(FlutterRunner.class)
public class MainActivityTest {
  @Rule
  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 app:connectedAndroidTest -Ptarget=`pwd`/../test_driver/<package_name>_e2e.dart

Firebase Test Lab #

If this is your first time testing with Firebase Test Lab, you'll need to follow the guides in the Firebase test lab documentation to set up a project.

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 app:assembleAndroidTest
./gradlew app:assembleDebug -Ptarget=<path_to_test>.dart
popd

Upload the build apks 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> \
  --results-dir=<RESULTS_DIRECTORY>

You can pass additional parameters on the command line, such as the devices you want to test on. See gcloud firebase test android run.

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

0.2.2+3 #

  • Remove the deprecated author: field from pubspec.yaml
  • Migrate the plugin to the pubspec platforms manifest.
  • Require Flutter SDK 1.10.0 or greater.

0.2.2+2 #

  • Adds an android dummy project to silence warnings and removes unnecessary .gitignore files.

0.2.2+1 #

  • Fix pedantic lints. Adds a missing await in the example test and some missing documentation.

0.2.2 #

  • Added a stub macos implementation
  • Added a macos example

0.2.1+1 #

  • Updated README.

0.2.1 #

  • Support the v2 Android embedder.
  • Print a warning if the plugin is not registered.
  • Updated method channel name.
  • Set a Flutter minimum SDK version.

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

example/README.md

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:


dependencies:
  e2e: ^0.2.2+3

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';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
97
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
98
Learn more about scoring.

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

  • Dart: 2.7.0
  • pana: 0.13.1+4
  • Flutter: 1.12.13+hotfix.4

Dependencies

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
archive 2.0.11
args 1.5.2
async 2.4.0
boolean_selector 1.0.5
charcode 1.1.2
collection 1.14.11 1.14.12
convert 2.1.1
crypto 2.1.3 2.1.4
image 2.1.4 2.1.9
matcher 0.12.6
meta 1.1.8
path 1.6.4
pedantic 1.8.0+1 1.9.0
petitparser 2.4.0
quiver 2.0.5 2.1.2+1
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.11
typed_data 1.1.6
vector_math 2.0.8
xml 3.5.0 3.6.1