Skip to content

Commit 48285ff

Browse files
author
Sebastian Roth
committed
Adds e2e testing capabilities for Android
1 parent e285f60 commit 48285ff

File tree

11 files changed

+268
-10
lines changed

11 files changed

+268
-10
lines changed

example/android/app/build.gradle

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ android {
3838
targetSdkVersion 29
3939
versionCode flutterVersionCode.toInteger()
4040
versionName flutterVersionName
41+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
4142
}
4243

4344
buildTypes {
@@ -51,4 +52,10 @@ android {
5152

5253
flutter {
5354
source '../..'
55+
}
56+
57+
dependencies {
58+
androidTestImplementation 'androidx.test:runner:1.2.0'
59+
androidTestImplementation 'androidx.test:rules:1.2.0'
60+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
5461
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.baseflow.googleapiavailability;
2+
3+
import androidx.test.rule.ActivityTestRule;
4+
import com.baseflow.googleapiavailabilityexample.EmbeddingV1Activity;
5+
import dev.flutter.plugins.e2e.FlutterTestRunner;
6+
import org.junit.Rule;
7+
import org.junit.runner.RunWith;
8+
9+
@RunWith(FlutterTestRunner.class)
10+
public class EmbeddingV1ActivityTest {
11+
12+
@Rule
13+
public ActivityTestRule<EmbeddingV1Activity> rule =
14+
new ActivityTestRule<>(EmbeddingV1Activity.class);
15+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.baseflow.googleapiavailability;
2+
3+
import androidx.test.rule.ActivityTestRule;
4+
import dev.flutter.plugins.e2e.FlutterTestRunner;
5+
import org.junit.Rule;
6+
import org.junit.runner.RunWith;
7+
8+
@RunWith(FlutterTestRunner.class)
9+
public class MainActivityTest {
10+
11+
@Rule
12+
public ActivityTestRule<io.flutter.embedding.android.FlutterActivity> rule = new ActivityTestRule<>(
13+
io.flutter.embedding.android.FlutterActivity.class);
14+
}

example/android/app/src/main/AndroidManifest.xml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
android:launchMode="singleTop"
1515
android:theme="@style/LaunchTheme"
1616
android:windowSoftInputMode="adjustResize">
17-
<meta-data android:name="flutterEmbedding" android:value="2"/>
17+
<meta-data android:name="flutterEmbedding" android:value="2"/>
1818
<!-- This keeps the window background of the activity showing
1919
until Flutter renders its first frame. It can be removed if
2020
there is no splash screen (such as the default splash screen
@@ -27,5 +27,14 @@
2727
<category android:name="android.intent.category.LAUNCHER" />
2828
</intent-filter>
2929
</activity>
30+
31+
<activity
32+
android:name=".EmbeddingV1Activity"
33+
android:theme="@style/LaunchTheme"
34+
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale"
35+
android:hardwareAccelerated="true"
36+
android:windowSoftInputMode="adjustResize" />
37+
38+
<meta-data android:name="flutterEmbedding" android:value="2"/>
3039
</application>
3140
</manifest>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.baseflow.googleapiavailabilityexample;
2+
3+
import android.os.Bundle;
4+
import com.baseflow.googleapiavailability.GoogleApiAvailabilityPlugin;
5+
import dev.flutter.plugins.e2e.E2EPlugin;
6+
import io.flutter.app.FlutterActivity;
7+
8+
public class EmbeddingV1Activity extends FlutterActivity {
9+
10+
@Override
11+
protected void onCreate(Bundle savedInstanceState) {
12+
super.onCreate(savedInstanceState);
13+
GoogleApiAvailabilityPlugin
14+
.registerWith(
15+
registrarFor("com.baseflow.googleapiavailability.GoogleApiAvailabilityPlugin"));
16+
E2EPlugin.registerWith(registrarFor("dev.flutter.plugins.e2e.E2EPlugin"));
17+
}
18+
}

example/pubspec.lock

Lines changed: 89 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,40 @@ packages:
6464
url: "https://pub.dartlang.org"
6565
source: hosted
6666
version: "0.1.2"
67+
e2e:
68+
dependency: "direct dev"
69+
description:
70+
name: e2e
71+
url: "https://pub.dartlang.org"
72+
source: hosted
73+
version: "0.4.0"
74+
file:
75+
dependency: transitive
76+
description:
77+
name: file
78+
url: "https://pub.dartlang.org"
79+
source: hosted
80+
version: "5.1.0"
6781
flutter:
6882
dependency: "direct main"
6983
description: flutter
7084
source: sdk
7185
version: "0.0.0"
86+
flutter_driver:
87+
dependency: "direct dev"
88+
description: flutter
89+
source: sdk
90+
version: "0.0.0"
7291
flutter_test:
7392
dependency: "direct dev"
7493
description: flutter
7594
source: sdk
7695
version: "0.0.0"
96+
fuchsia_remote_debug_protocol:
97+
dependency: transitive
98+
description: flutter
99+
source: sdk
100+
version: "0.0.0"
77101
google_api_availability:
78102
dependency: "direct dev"
79103
description:
@@ -88,6 +112,20 @@ packages:
88112
url: "https://pub.dartlang.org"
89113
source: hosted
90114
version: "2.1.4"
115+
intl:
116+
dependency: transitive
117+
description:
118+
name: intl
119+
url: "https://pub.dartlang.org"
120+
source: hosted
121+
version: "0.16.1"
122+
json_rpc_2:
123+
dependency: transitive
124+
description:
125+
name: json_rpc_2
126+
url: "https://pub.dartlang.org"
127+
source: hosted
128+
version: "2.1.0"
91129
matcher:
92130
dependency: transitive
93131
description:
@@ -116,6 +154,27 @@ packages:
116154
url: "https://pub.dartlang.org"
117155
source: hosted
118156
version: "2.4.0"
157+
platform:
158+
dependency: transitive
159+
description:
160+
name: platform
161+
url: "https://pub.dartlang.org"
162+
source: hosted
163+
version: "2.2.1"
164+
process:
165+
dependency: transitive
166+
description:
167+
name: process
168+
url: "https://pub.dartlang.org"
169+
source: hosted
170+
version: "3.0.12"
171+
pub_semver:
172+
dependency: transitive
173+
description:
174+
name: pub_semver
175+
url: "https://pub.dartlang.org"
176+
source: hosted
177+
version: "1.4.3"
119178
quiver:
120179
dependency: transitive
121180
description:
@@ -156,6 +215,13 @@ packages:
156215
url: "https://pub.dartlang.org"
157216
source: hosted
158217
version: "1.0.5"
218+
sync_http:
219+
dependency: transitive
220+
description:
221+
name: sync_http
222+
url: "https://pub.dartlang.org"
223+
source: hosted
224+
version: "0.2.0"
159225
term_glyph:
160226
dependency: transitive
161227
description:
@@ -184,6 +250,27 @@ packages:
184250
url: "https://pub.dartlang.org"
185251
source: hosted
186252
version: "2.0.8"
253+
vm_service_client:
254+
dependency: transitive
255+
description:
256+
name: vm_service_client
257+
url: "https://pub.dartlang.org"
258+
source: hosted
259+
version: "0.2.6+2"
260+
web_socket_channel:
261+
dependency: transitive
262+
description:
263+
name: web_socket_channel
264+
url: "https://pub.dartlang.org"
265+
source: hosted
266+
version: "1.1.0"
267+
webdriver:
268+
dependency: transitive
269+
description:
270+
name: webdriver
271+
url: "https://pub.dartlang.org"
272+
source: hosted
273+
version: "2.1.2"
187274
xml:
188275
dependency: transitive
189276
description:
@@ -192,5 +279,5 @@ packages:
192279
source: hosted
193280
version: "3.5.0"
194281
sdks:
195-
dart: ">=2.4.0 <3.0.0"
196-
flutter: ">=1.12.8 <2.0.0"
282+
dart: ">=2.5.0 <3.0.0"
283+
flutter: ">=1.12.13+hotfix.6 <2.0.0"

example/pubspec.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ name: google_api_availability_example
22
description: Demonstrates how to use the google_api_availability plugin.
33
version: 1.0.0+1
44

5-
environment:
6-
sdk: ">=2.0.0 <3.0.0"
7-
85
dependencies:
96
flutter:
107
sdk: flutter
@@ -13,6 +10,9 @@ dependencies:
1310
dev_dependencies:
1411
flutter_test:
1512
sdk: flutter
13+
e2e: ^0.4.0
14+
flutter_driver:
15+
sdk: flutter
1616

1717
google_api_availability:
1818
path: ../
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import 'package:flutter_test/flutter_test.dart';
2+
import 'package:e2e/e2e.dart';
3+
import 'package:google_api_availability/google_api_availability.dart';
4+
5+
void main() {
6+
E2EWidgetsFlutterBinding.ensureInitialized();
7+
8+
testWidgets('can check for availability', (WidgetTester tester) async {
9+
// Depending on the target device, this should not throw but simply return a value.
10+
await GoogleApiAvailability.instance
11+
.checkGooglePlayServicesAvailability(false);
12+
});
13+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import 'dart:async';
2+
3+
import 'package:e2e/e2e_driver.dart' as e2e;
4+
5+
Future<void> main() async => e2e.main();

0 commit comments

Comments
 (0)