[go: nahoru, domu]

Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
Rename instrumentation_adapter plugin to e2e plugin (#2161)
Browse files Browse the repository at this point in the history
* Rename instrumentation_adapter plugin to e2e plugin
* Refactored test, demonstrate reading the exit code
* Updated README
  • Loading branch information
collinjackson committed Oct 8, 2019
1 parent a9153ef commit bf17b0a
Show file tree
Hide file tree
Showing 78 changed files with 112 additions and 72 deletions.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 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.
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# instrumentation_adapter
# e2e

Adapts flutter_test results as Android instrumentation tests, making them usable
for Firebase Test Lab and other Android CI providers.
Expand All @@ -7,24 +7,59 @@ iOS support is not available yet, but is planned in the future.

## Usage

Add a dependency on the `instrumentation_adapter` package in the
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 `InstrumentationAdapterFlutterBinding.ensureInitialized()` at the start
of a test file, e.g.

```dart
import 'package:instrumentation_adapter/instrumentation_adapter.dart';
import 'package:e2e/e2e.dart';
void main() {
InstrumentationAdapterFlutterBinding.ensureInitialized();
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));
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
Expand All @@ -34,7 +69,7 @@ this test file MainActivityTest.java or another name of your choice.
package com.example.myapp;
import androidx.test.rule.ActivityTestRule;
import dev.flutter.plugins.instrumentationadapter.FlutterRunner;
import dev.flutter.plugins.e2e.FlutterRunner;
import org.junit.Rule;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -67,7 +102,16 @@ dependencies {
}
```

Use gradle commands to build an instrumentation test for Android.
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
Expand All @@ -90,14 +134,4 @@ gcloud firebase test android run --type instrumentation \
--results-dir=<RESULTS_DIRECTORY>
```

## Flutter driver support

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

```dart
final FlutterDriver driver = await FlutterDriver.connect();
final String result = await driver.requestData(null, timeout: const Duration(minutes: 1));
driver.close();
exit(result == 'pass' ? 0 : 1);
```
iOS support for Firebase Test Lab is not yet available, but is planned.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
group 'com.example.instrumentation_adapter'
group 'com.example.e2e'
version '1.0-SNAPSHOT'

buildscript {
Expand Down
1 change: 1 addition & 0 deletions packages/e2e/android/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = 'e2e'
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="dev.flutter.instrumentation_adapter">
package="dev.flutter.e2e">
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package dev.flutter.plugins.instrumentationadapter;
package dev.flutter.plugins.e2e;

import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
Expand All @@ -12,17 +12,17 @@
import java.util.Map;
import java.util.concurrent.CompletableFuture;

/** InstrumentationAdapterPlugin */
public class InstrumentationAdapterPlugin implements MethodCallHandler {
/** E2EPlugin */
public class E2EPlugin implements MethodCallHandler {

public static CompletableFuture<Map<String, String>> testResults = new CompletableFuture<>();

private static final String CHANNEL = "dev.flutter/InstrumentationAdapterFlutterBinding";
private static final String CHANNEL = "plugins.flutter.dev/e2e";

/** Plugin registration. */
public static void registerWith(Registrar registrar) {
final MethodChannel channel = new MethodChannel(registrar.messenger(), CHANNEL);
channel.setMethodCallHandler(new InstrumentationAdapterPlugin());
channel.setMethodCallHandler(new E2EPlugin());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package dev.flutter.plugins.instrumentationadapter;
package dev.flutter.plugins.e2e;

import android.app.Activity;
import androidx.test.rule.ActivityTestRule;
Expand Down Expand Up @@ -49,7 +49,7 @@ public Description getDescription() {
public void run(RunNotifier notifier) {
Map<String, String> results = null;
try {
results = InstrumentationAdapterPlugin.testResults.get();
results = E2EPlugin.testResults.get();
} catch (ExecutionException | InterruptedException e) {
throw new IllegalThreadStateException("Unable to get test results");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# instrumentation_adapter_example
# e2e_example

Demonstrates how to use the instrumentation_adapter plugin.
Demonstrates how to use the e2e plugin.

## Getting Started

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ android {

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.instrumentation_adapter_example"
applicationId "com.example.e2e_example"
minSdkVersion 16
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.instrumentation_adapter_example;
package com.example.e2e_example;

import androidx.test.rule.ActivityTestRule;
import dev.flutter.plugins.instrumentationadapter.FlutterRunner;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.instrumentation_adapter_example">
package="com.example.e2e_example">
<!-- Flutter needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.instrumentation_adapter_example">
package="com.example.e2e_example">

<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
Expand All @@ -8,7 +8,7 @@
FlutterApplication and put your custom class here. -->
<application
android:name="io.flutter.app.FlutterApplication"
android:label="instrumentation_adapter_example"
android:label="e2e_example"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.instrumentation_adapter_example;
package com.example.e2e_example;

import android.os.Bundle;
import io.flutter.app.FlutterActivity;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.instrumentation_adapter_example">
package="com.example.e2e_example">
<!-- Flutter needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ org.gradle.jvmargs=-Xmx1536M

android.useAndroidX=true
android.enableJetifier=true
android.enableR8=true
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>instrumentation_adapter_example</string>
<string>e2e_example</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: instrumentation_adapter_example
description: Demonstrates how to use the instrumentation_adapter plugin.
name: e2e_example
description: Demonstrates how to use the e2e plugin.
publish_to: 'none'

environment:
Expand All @@ -16,7 +16,7 @@ dev_dependencies:
sdk: flutter
flutter_driver:
sdk: flutter
instrumentation_adapter:
e2e:
path: ../

# For information on the generic Dart part of this file, see the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
import 'dart:io' show Platform;
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:instrumentation_adapter/instrumentation_adapter.dart';
import 'package:e2e/e2e.dart';

import 'package:instrumentation_adapter_example/main.dart';
import 'package:e2e_example/main.dart';

void main() {
InstrumentationAdapterFlutterBinding.ensureInitialized();
E2EWidgetsFlutterBinding.ensureInitialized();
testWidgets('verify text', (WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(MyApp());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import 'dart:async';
import 'dart:io';

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));
final String result =
await driver.requestData(null, timeout: const Duration(minutes: 1));
driver.close();
exit(result == 'pass' ? 0 : 1);
}
File renamed without changes.
4 changes: 4 additions & 0 deletions packages/e2e/ios/Classes/E2EPlugin.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#import <Flutter/Flutter.h>

@interface E2EPlugin : NSObject <FlutterPlugin>
@end
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#import "InstrumentationAdapterPlugin.h"
#import "E2EPlugin.h"

@implementation InstrumentationAdapterPlugin
@implementation E2EPlugin
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
FlutterMethodChannel* channel = [FlutterMethodChannel
methodChannelWithName:@"dev.flutter/InstrumentationAdapterFlutterBinding"
binaryMessenger:[registrar messenger]];
InstrumentationAdapterPlugin* instance = [[InstrumentationAdapterPlugin alloc] init];
FlutterMethodChannel* channel =
[FlutterMethodChannel methodChannelWithName:@"plugins.flutter.dev/e2e"
binaryMessenger:[registrar messenger]];
E2EPlugin* instance = [[E2EPlugin alloc] init];
[registrar addMethodCallDelegate:instance channel:channel];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html
#
Pod::Spec.new do |s|
s.name = 'instrumentation_adapter'
s.name = 'e2e'
s.version = '0.0.1'
s.summary = 'Instrumentation adapter.'
s.summary = 'Adapter for e2e tests.'
s.description = <<-DESC
Runs tests that use the flutter_test API as integration tests.
DESC
s.homepage = 'https://github.com/flutter/plugins/tree/master/packages/instrumentation_adapter'
s.homepage = 'https://github.com/flutter/plugins/tree/master/packages/e2e'
s.license = { :file => '../LICENSE' }
s.author = { 'Flutter Team' => 'flutter-dev@googlegroups.com' }
s.source = { :path => '.' }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ import 'package:flutter/widgets.dart';

/// A subclass of [LiveTestWidgetsFlutterBinding] that reports tests results
/// on a channel to adapt them to native instrumentation test format.
class InstrumentationAdapterFlutterBinding
extends LiveTestWidgetsFlutterBinding {
InstrumentationAdapterFlutterBinding() {
class E2EWidgetsFlutterBinding extends LiveTestWidgetsFlutterBinding {
E2EWidgetsFlutterBinding() {
// TODO(jackson): Report test results as they arrive
tearDownAll(() async {
try {
Expand All @@ -29,14 +28,14 @@ class InstrumentationAdapterFlutterBinding

static WidgetsBinding ensureInitialized() {
if (WidgetsBinding.instance == null) {
InstrumentationAdapterFlutterBinding();
E2EWidgetsFlutterBinding();
}
assert(WidgetsBinding.instance is InstrumentationAdapterFlutterBinding);
assert(WidgetsBinding.instance is E2EWidgetsFlutterBinding);
return WidgetsBinding.instance;
}

static const MethodChannel _channel =
MethodChannel('dev.flutter/InstrumentationAdapterFlutterBinding');
MethodChannel('plugins.flutter.dev/e2e');

static Map<String, String> _results = <String, String>{};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: instrumentation_adapter
name: e2e
description: Runs tests that use the flutter_test API as integration tests.
version: 0.1.4
version: 0.2.0
author: Flutter Team <flutter-dev@googlegroups.com>
homepage: https://github.com/flutter/plugins/tree/master/packages/instrumentation_adapter
homepage: https://github.com/flutter/plugins/tree/master/packages/e2e

environment:
sdk: ">=2.1.0 <3.0.0"
Expand All @@ -15,5 +15,5 @@ dependencies:

flutter:
plugin:
androidPackage: dev.flutter.plugins.instrumentationadapter
pluginClass: InstrumentationAdapterPlugin
androidPackage: dev.flutter.plugins.e2e
pluginClass: E2EPlugin
1 change: 0 additions & 1 deletion packages/instrumentation_adapter/android/settings.gradle

This file was deleted.

Loading

0 comments on commit bf17b0a

Please sign in to comment.