Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
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
9 changes: 9 additions & 0 deletions packages/espresso/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## 0.4.0+26

* Adopts `code-excerpt` for the README's Dart driver snippet so it is
validated against compilable, analyzed source, and updates it to use
`integration_test`'s driver instead of the deprecated `flutter_driver`
extension.
* Adopts `code-excerpt` for the README's `network_security_config.xml` and
`build.gradle.kts` dependencies snippets.

## 0.4.0+25

* Bumps com.google.guava:guava from 33.5.0-android to 33.6.0-android.
Expand Down
36 changes: 20 additions & 16 deletions packages/espresso/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# espresso
<?code-excerpt path-base="example"?>

Provides bindings for Espresso tests of Flutter Android apps.

Expand All @@ -18,8 +19,8 @@ Add ```android:networkSecurityConfig="@xml/network_security_config"``` in the ``

Then you will need to create a `network_security_config.xml` in the `res/xml/` directory.

<?code-excerpt "android/app/src/debug/res/xml/network_security_config.xml (network_security_config)"?>
```xml
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<!-- Cleartext is needed for Espresso testing. -->
<base-config cleartextTrafficPermitted="true">
Expand All @@ -32,15 +33,21 @@ For example, the Espresso example app has this file in the location `example/and
It is best to put this in a debug or androidTest
AndroidManifest.xml so that you don't ship it to end users. (See the example app of this package.)

Add the following dependencies in android/app/build.gradle:
Add the following dependencies in android/app/build.gradle.kts:

```groovy
<?code-excerpt "android/app/build.gradle.kts (test_dependencies)"?>
```kotlin
dependencies {
testImplementation("junit:junit:4.13.2")
testImplementation("com.google.truth:truth:1.1.3")
// ···
api("androidx.test:core:1.6.1")
// ···
androidTestImplementation("androidx.test:runner:1.6.1")
// ···
androidTestImplementation("com.google.truth:truth:1.1.3")
// ···
androidTestImplementation("androidx.test.espresso:espresso-core:3.6.1")
api("androidx.test:core:1.2.0")
// ···
}
```

Expand Down Expand Up @@ -86,25 +93,22 @@ public class MainActivityTest {
}
```

You'll need to create a test app that enables the Flutter driver extension.
You can put this in your test_driver/ folder, e.g. test_driver/example.dart.
Replace `<app_package_name>` with the package name of your app. If you're
developing a plugin, this will be the package name of the example app.
You'll need to create a driver script that hands off to the
[`integration_test`](https://pub.dev/packages/integration_test) package so
`flutter drive`/Espresso can run your Dart integration tests. Put this in your
`test_driver/` folder, e.g. `test_driver/integration_test.dart`:

<?code-excerpt "test_driver/integration_test.dart (Driver)"?>
```dart
import 'package:flutter_driver/driver_extension.dart';
import 'package:<app_package_name>/main.dart' as app;
import 'package:integration_test/integration_test_driver.dart';

void main() {
enableFlutterDriverExtension();
app.main();
}
Future<void> main() => integrationDriver();
```

The following command line command runs the test locally:

```sh
./gradlew app:connectedAndroidTest -Ptarget=`pwd`/../test_driver/example.dart
./gradlew app:connectedAndroidTest -Ptarget=`pwd`/../test_driver/integration_test.dart
Comment thread
stuartmorgan-g marked this conversation as resolved.
```

Espresso tests can also be run on [Firebase Test Lab](https://firebase.google.com/docs/test-lab):
Expand Down
2 changes: 0 additions & 2 deletions packages/espresso/ci_config.yaml

This file was deleted.

12 changes: 12 additions & 0 deletions packages/espresso/example/android/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,36 @@ flutter {
source = "../.."
}

// #docregion test_dependencies
dependencies {
testImplementation("junit:junit:4.13.2")
// #enddocregion test_dependencies

// Multidex
implementation("androidx.multidex:multidex:2.0.1")

// Core library
// #docregion test_dependencies
api("androidx.test:core:1.6.1")
// #enddocregion test_dependencies

// AndroidJUnitRunner and JUnit Rules
// #docregion test_dependencies
androidTestImplementation("androidx.test:runner:1.6.1")
// #enddocregion test_dependencies
androidTestImplementation("androidx.test:rules:1.6.1")

// Assertions
androidTestImplementation("androidx.test.ext:junit:1.2.1")
androidTestImplementation("androidx.test.ext:truth:1.6.0")
// #docregion test_dependencies
androidTestImplementation("com.google.truth:truth:1.1.3")
// #enddocregion test_dependencies

// Espresso dependencies
// #docregion test_dependencies
androidTestImplementation("androidx.test.espresso:espresso-core:3.6.1")
// #enddocregion test_dependencies
androidTestImplementation("androidx.test.espresso:espresso-contrib:3.6.1")
androidTestImplementation("androidx.test.espresso:espresso-intents:3.6.1")
androidTestImplementation("androidx.test.espresso:espresso-accessibility:3.6.1")
Expand All @@ -71,4 +81,6 @@ dependencies {
// dependency to appear on your APK's compile classpath or the test APK
// classpath.
androidTestImplementation("androidx.test.espresso:espresso-idling-resource:3.6.1")
// #docregion test_dependencies
}
// #enddocregion test_dependencies
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<!--#docregion network_security_config-->
<network-security-config>
<!-- Cleartext is needed for Espresso testing. -->
<base-config cleartextTrafficPermitted="true">
</base-config>
</network-security-config>
<!--#enddocregion network_security_config-->
2 changes: 2 additions & 0 deletions packages/espresso/example/test_driver/integration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// #docregion Driver
import 'package:integration_test/integration_test_driver.dart';

Future<void> main() => integrationDriver();
// #enddocregion Driver
2 changes: 1 addition & 1 deletion packages/espresso/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Java classes for testing Flutter apps using Espresso.
Allows driving Flutter widgets from a native Espresso test.
repository: https://github.com/flutter/packages/tree/main/packages/espresso
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+espresso%22
version: 0.4.0+25
version: 0.4.0+26

environment:
sdk: ^3.10.0
Expand Down
Loading