Adapts flutter_test results as Android instrumentation tests, making them usable for Firebase Test Lab and other Android CI providers.

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


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

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

import 'package:instrumentation_adapter/instrumentation_adapter.dart';

void main() {
  testWidgets("failing test example", (WidgetTester tester) async {
    expect(2 + 2, equals(5));

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 or another name of your choice.

package com.example.myapp;

import androidx.test.rule.ActivityTestRule;
import dev.flutter.plugins.instrumentationadapter.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'

    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

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> \

Flutter driver support

InstrumentationAdapterFlutterBinding also reports test results to FlutterDriver when run on the command line via flutter drive.

  final FlutterDriver driver = await FlutterDriver.connect();
  final String result = await driver.requestData(null, timeout: const Duration(minutes: 1));
  exit(result == 'pass' ? 0 : 1);