From 09ceba4d69623f8c4d50f059bc9ea2a08fa51cc9 Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Wed, 15 Apr 2020 10:22:05 -0700 Subject: [PATCH] Revert "[e2e] Replaces the check for ActivityTestRule (#2633)" This reverts commit a811e63466c3afcdcbde82862178bb23b39457a7. --- packages/e2e/CHANGELOG.md | 4 --- .../plugins/e2e/FlutterTestRunner.java | 14 +++-------- .../MainActivityWithPermissionTest.java | 25 ------------------- packages/e2e/pubspec.yaml | 2 +- 4 files changed, 5 insertions(+), 40 deletions(-) delete mode 100644 packages/e2e/example/android/app/src/androidTest/java/com/example/e2e_example/MainActivityWithPermissionTest.java diff --git a/packages/e2e/CHANGELOG.md b/packages/e2e/CHANGELOG.md index 305a288d949a..79969126bb70 100644 --- a/packages/e2e/CHANGELOG.md +++ b/packages/e2e/CHANGELOG.md @@ -1,7 +1,3 @@ -## 0.4.1 - -* Adds support for Android E2E tests that utilize other @Rule's, like GrantPermissionRule. - ## 0.4.0 * **Breaking change** Driver request_data call's response has changed to diff --git a/packages/e2e/android/src/main/java/dev/flutter/plugins/e2e/FlutterTestRunner.java b/packages/e2e/android/src/main/java/dev/flutter/plugins/e2e/FlutterTestRunner.java index 78f0c3c5bac2..f214cd7ce3fe 100644 --- a/packages/e2e/android/src/main/java/dev/flutter/plugins/e2e/FlutterTestRunner.java +++ b/packages/e2e/android/src/main/java/dev/flutter/plugins/e2e/FlutterTestRunner.java @@ -4,24 +4,23 @@ package dev.flutter.plugins.e2e; +import android.app.Activity; import android.util.Log; import androidx.test.rule.ActivityTestRule; import java.lang.reflect.Field; import java.util.Map; import java.util.concurrent.ExecutionException; import org.junit.Rule; -import org.junit.rules.TestRule; import org.junit.runner.Description; import org.junit.runner.Runner; import org.junit.runner.notification.Failure; import org.junit.runner.notification.RunNotifier; public class FlutterTestRunner extends Runner { - private static final String TAG = "FlutterTestRunner"; final Class testClass; - TestRule rule = null; + ActivityTestRule rule = null; public FlutterTestRunner(Class testClass) { super(); @@ -33,10 +32,7 @@ public FlutterTestRunner(Class testClass) { if (field.isAnnotationPresent(Rule.class)) { try { Object instance = testClass.newInstance(); - if (field.get(instance) instanceof ActivityTestRule) { - rule = (TestRule) field.get(instance); - break; - } + rule = (ActivityTestRule) field.get(instance); } catch (InstantiationException | IllegalAccessException e) { // This might occur if the developer did not make the rule public. // We could call field.setAccessible(true) but it seems better to throw. @@ -57,9 +53,7 @@ public void run(RunNotifier notifier) { throw new RuntimeException("Unable to run tests due to missing activity rule"); } try { - if (rule instanceof ActivityTestRule) { - ((ActivityTestRule) rule).launchActivity(null); - } + rule.launchActivity(null); } catch (RuntimeException e) { Log.v(TAG, "launchActivity failed, possibly because the activity was already running. " + e); Log.v( diff --git a/packages/e2e/example/android/app/src/androidTest/java/com/example/e2e_example/MainActivityWithPermissionTest.java b/packages/e2e/example/android/app/src/androidTest/java/com/example/e2e_example/MainActivityWithPermissionTest.java deleted file mode 100644 index 90218e8724a9..000000000000 --- a/packages/e2e/example/android/app/src/androidTest/java/com/example/e2e_example/MainActivityWithPermissionTest.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.example.e2e_example; - -import android.Manifest.permission; -import androidx.test.rule.ActivityTestRule; -import androidx.test.rule.GrantPermissionRule; -import dev.flutter.plugins.e2e.FlutterTestRunner; -import org.junit.Rule; -import org.junit.runner.RunWith; - -/** - * Demonstrates how a E2E test on Android can be run with permissions already granted. This is - * helpful if developers want to test native App behavior that depends on certain system service - * results which are guarded with permissions. - */ -@RunWith(FlutterTestRunner.class) -public class MainActivityWithPermissionTest { - - @Rule - public GrantPermissionRule permissionRule = - GrantPermissionRule.grant(permission.ACCESS_COARSE_LOCATION); - - @Rule - public ActivityTestRule rule = - new ActivityTestRule<>(MainActivity.class, true, false); -} diff --git a/packages/e2e/pubspec.yaml b/packages/e2e/pubspec.yaml index d3a86cf65f21..1af3ab911447 100644 --- a/packages/e2e/pubspec.yaml +++ b/packages/e2e/pubspec.yaml @@ -1,6 +1,6 @@ name: e2e description: Runs tests that use the flutter_test API as integration tests. -version: 0.4.1 +version: 0.4.0 homepage: https://github.com/flutter/plugins/tree/master/packages/e2e environment: