Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
1743eab
Initial copy of e2e plugin renamed to espresso
collinjackson Nov 26, 2019
0bf791e
Switch to a new project based on template plugin
collinjackson Nov 26, 2019
f47c5a4
Update example app to be a button app
collinjackson Nov 26, 2019
45bf214
switch to Java
collinjackson Nov 26, 2019
195bb22
Add example Espresso test
collinjackson Nov 26, 2019
fded8ad
Midpoint check-in while addressing dependency errors
collinjackson Nov 26, 2019
60da0af
Demonstration of Espresso tests passing
collinjackson Nov 26, 2019
4f65053
All tests pass
collinjackson Nov 26, 2019
7c77635
Add shared preferences integration test
collinjackson Nov 26, 2019
86f133c
Fix test to match internal version
collinjackson Nov 26, 2019
02adfc8
Tests pass for shared prefs plugin
collinjackson Nov 26, 2019
f343591
Open source Espresso files
collinjackson Nov 26, 2019
521eb6c
License
collinjackson Dec 6, 2019
f2e0e56
SDK constraints
collinjackson Dec 6, 2019
6b86f04
Update README, changelog, remove test
collinjackson Dec 6, 2019
0b70161
Revert shared_preferences
collinjackson Dec 6, 2019
ce9de53
Update README.md
collinjackson Dec 7, 2019
cc2ebe5
Update README to make it clear this package is Android-only
collinjackson Dec 9, 2019
11b38af
Update licenses
collinjackson Dec 9, 2019
da89fee
Merge remote-tracking branch 'cj/new_espresso_plugin' into new_espres…
collinjackson Dec 9, 2019
211e358
remove commented dependencies
collinjackson Dec 9, 2019
b823741
More README updates
collinjackson Dec 9, 2019
5a1d274
Add a click test
collinjackson Dec 9, 2019
226a0d6
Fix build error
collinjackson Dec 9, 2019
2d0d9a1
More README updates
collinjackson Dec 9, 2019
0a2b5ab
fix file that wasn't meant to be checked in
collinjackson Dec 9, 2019
56360ff
Update README
collinjackson Dec 9, 2019
e3d340c
Merge remote-tracking branch 'origin/master' into new_espresso_plugin
collinjackson Dec 10, 2019
5377d27
Fix build failure
collinjackson Dec 10, 2019
8663ebd
Update README.md
collinjackson Dec 10, 2019
f69d012
Update README to clarify that iOS example is for the bots.
collinjackson Jan 9, 2020
a33410d
Code review feedback on plaintext traffic
collinjackson Jan 9, 2020
3a00269
Update README.md
collinjackson Jan 9, 2020
e5c1ae1
reformat
collinjackson Jan 9, 2020
5bf41b2
update pubspec.yaml
collinjackson Jan 9, 2020
9a85ad9
remove unused test
collinjackson Jan 9, 2020
d69e407
reformat
collinjackson Jan 9, 2020
6b6ff85
Merge remote-tracking branch 'origin/master' into new_espresso_plugin
collinjackson Jan 9, 2020
acef95e
Merge remote-tracking branch 'cj/new_espresso_plugin' into new_espres…
collinjackson Jan 9, 2020
a5a9c46
Fix analyzer issues
collinjackson Jan 9, 2020
8b6542b
fix ios build
collinjackson Jan 9, 2020
d18b2a0
remove lib/espresso.dart
collinjackson Jan 9, 2020
8129481
reformat
collinjackson Jan 9, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Switch to a new project based on template plugin
  • Loading branch information
collinjackson committed Dec 6, 2019
commit 0bf791e10d4dc3381ee370e472cc1d9a0c35b19c
4 changes: 2 additions & 2 deletions packages/espresso/.metadata
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# This file should be version controlled and should not be manually edited.

version:
revision: 3374ee380b499d99c50ed6dfdd45510aa8318741
channel: master
revision: 0190e40457d43e17bdfaf046dfa634cbc5bf28b9
channel: unknown

project_type: plugin
53 changes: 1 addition & 52 deletions packages/espresso/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,54 +1,3 @@
## 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 espresso.
* Refactored example app test.
* **Breaking change**. Renamed `InstrumentationAdapterFlutterBinding` to
`espressoWidgetsFlutterBinding`.
* 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
* TODO: Describe initial release.
28 changes: 1 addition & 27 deletions packages/espresso/LICENSE
Original file line number Diff line number Diff line change
@@ -1,27 +1 @@
// Copyright 2019 The Chromium Authors. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
TODO: Add your license here.
158 changes: 9 additions & 149 deletions packages/espresso/README.md
Original file line number Diff line number Diff line change
@@ -1,154 +1,14 @@
# espresso

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.
A new flutter plugin project.

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

## Usage
This project is a starting point for a Flutter
[plug-in package](https://flutter.dev/developing-packages/),
a specialized package that includes platform-specific implementation code for
Android and/or iOS.

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

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

```dart
import 'package:espresso/espresso.dart';

void main() {
espressoWidgetsFlutterBinding.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 espresso tests in the `test/` folder of the app or package.
For example apps, if the espresso test references example app code, it should go in
`example/test/`. It is also acceptable to put espresso tests in `test_driver/` folder
so that they're alongside the runner app (see below).

## Using Flutter driver to run tests

`espressoWidgetsTestBinding` 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>_espresso_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>_espresso.dart
```

To test plugin APIs using Flutter driver:

```
cd example
flutter drive --driver=test_driver/<package_name>_test.dart test/<package_name>_espresso.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.espresso.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 espresso test on a local Android device (emulated or physical):

```
./gradlew app:connectedAndroidTest -Ptarget=`pwd`/../test_driver/<package_name>_espresso.dart
```

## Firebase Test Lab

If this is you first time testing with Firebase Test Lab,
you'll need to follow the guides in the
[Firebase test lab documentation](https://firebase.google.com/docs/test-lab/?gclid=EAIaIQobChMIs5qVwqW25QIV8iCtBh3DrwyUEAAYASAAEgLFU_D_BwE)
to set up a project.

To run an espresso 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](https://cloud.google.com/sdk/gcloud/reference/firebase/test/android/run).

iOS support for Firebase Test Lab is not yet available, but is planned.
For help getting started with Flutter, view our
[online documentation](https://flutter.dev/docs), which offers tutorials,
samples, guidance on mobile development, and a full API reference.
11 changes: 0 additions & 11 deletions packages/espresso/analysis_options.yaml

This file was deleted.

43 changes: 10 additions & 33 deletions packages/espresso/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ group 'com.example.espresso'
version '1.0-SNAPSHOT'

buildscript {
ext.kotlin_version = '1.3.50'
repositories {
google()
jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.android.tools.build:gradle:3.5.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

Expand All @@ -20,48 +22,23 @@ rootProject.allprojects {
}

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

android {
compileSdkVersion 28

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
defaultConfig {
minSdkVersion 16
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
lintOptions {
disable 'InvalidPackage'
}
dependencies {
api 'junit:junit:4.12'

// https://developer.android.com/jetpack/androidx/releases/test/#1.2.0
api 'androidx.test:runner:1.2.0'
api 'androidx.test:rules:1.2.0'
api 'androidx.test.espresso:espresso-core:3.2.0'
}
}

// TODO(amirh): Remove this hack once androidx.lifecycle is included on stable. https://github.com/flutter/flutter/issues/42348
afterEvaluate {
def containsEmbeddingDependencies = false
for (def configuration : configurations.all) {
for (def dependency : configuration.dependencies) {
if (dependency.group == 'io.flutter' &&
dependency.name.startsWith('flutter_embedding') &&
dependency.isTransitive())
{
containsEmbeddingDependencies = true
break
}
}
}
if (!containsEmbeddingDependencies) {
android {
dependencies {
def lifecycle_version = "2.1.0"
api "androidx.lifecycle:lifecycle-common-java8:$lifecycle_version"
api "androidx.lifecycle:lifecycle-runtime:$lifecycle_version"
}
}
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
4 changes: 3 additions & 1 deletion packages/espresso/android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
org.gradle.jvmargs=-Xmx1536M

android.enableR8=true
android.useAndroidX=true
android.enableJetifier=true
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip
2 changes: 1 addition & 1 deletion packages/espresso/android/src/main/AndroidManifest.xml
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.espresso">
package="com.example.espresso">
</manifest>
Loading