|
2 | 2 |
|
3 | 3 | A new flutter plugin project.
|
4 | 4 |
|
5 |
| -## Getting Started |
| 5 | +This package provides bindings for Espresso tests of Flutter apps. |
6 | 6 |
|
| 7 | +## Installation |
7 | 8 |
|
| 9 | +See the example app for test layout. |
8 | 10 |
|
9 | 11 | Add ```android:usesCleartextTraffic="true"``` to your ```<application>``` in your AndroidManifest.xml.
|
| 12 | + |
| 13 | +## Sample usage: |
| 14 | + |
| 15 | +``` |
| 16 | +@RunWith(AndroidJUnit4.class) |
| 17 | +public final class SharedPreferencesIntegrationTest { |
| 18 | +
|
| 19 | + @Rule |
| 20 | + public ActivityTestRule<MainActivity> myActivityTestRule = |
| 21 | + new ActivityTestRule<>(MainActivity.class, true, false); |
| 22 | +
|
| 23 | + @Before |
| 24 | + public void setUp() { |
| 25 | + ActivityScenario.launch(MainActivity.class); |
| 26 | + } |
| 27 | +
|
| 28 | + @Test |
| 29 | + public void tapToCheckPersistentData() throws Exception { |
| 30 | + onFlutterWidget(FlutterMatchers.withTooltip("Clear")).perform(FlutterActions.click()); |
| 31 | + onFlutterWidget(FlutterMatchers.withTooltip("Increment")).perform(FlutterActions.click()); |
| 32 | + onFlutterWidget(FlutterMatchers.withValueKey("ResultText")).check( |
| 33 | + FlutterAssertions.matches(FlutterMatchers.withText( |
| 34 | + "Button tapped 1 time.\n\nThis should persist across restarts." |
| 35 | + ))); |
| 36 | + // kill the app |
| 37 | + pressBackUnconditionally(); |
| 38 | + // reopen the application |
| 39 | + myActivityTestRule.launchActivity(null); |
| 40 | + onFlutterWidget(FlutterMatchers.withValueKey("ResultText")).check( |
| 41 | + FlutterAssertions.matches( |
| 42 | + FlutterMatchers.withText( |
| 43 | + "Button tapped 1 time.\n\nThis should persist across restarts."))); |
| 44 | + } |
| 45 | +} |
| 46 | +``` |
| 47 | + |
| 48 | +The following command line command runs the test locally: |
| 49 | + |
| 50 | +``` |
| 51 | +./gradlew app:connectedAndroidTest -Ptarget=`pwd`/../test_driver/shared_preferences.dart |
| 52 | +``` |
| 53 | + |
| 54 | +Tests can also be uploaded to Firebase Test Lab: |
| 55 | + |
| 56 | +``` |
| 57 | +./gradlew app:assembleAndroidTest |
| 58 | +./gradlew app:assembleDebug -Ptarget=<path_to_test>.dart |
| 59 | +gcloud auth activate-service-account --key-file=<PATH_TO_KEY_FILE> |
| 60 | +gcloud --quiet config set project <PROJECT_NAME> |
| 61 | +gcloud firebase test android run --type instrumentation \ |
| 62 | + --app build/app/outputs/apk/debug/app-debug.apk \ |
| 63 | + --test build/app/outputs/apk/androidTest/debug/app-debug-androidTest.apk\ |
| 64 | + --timeout 2m \ |
| 65 | + --results-bucket=<RESULTS_BUCKET> \ |
| 66 | + --results-dir=<RESULTS_DIRECTORY> |
| 67 | +``` |
| 68 | + |
| 69 | +This guarantees that UrlLauncherPlatform.instance cannot be set to an object that `implements` |
| 70 | +UrlLauncherPlatform (it can only be set to an object that `extends` UrlLauncherPlatform). |
| 71 | + |
0 commit comments