Skip to content

Commit b3f9e58

Browse files
authored
Update integration testing docs for Android and iOS. (#11680)
_Description of what this PR is changing or adding, and why:_ Separate the iOS and Android integration testing steps so that it's easier for our Android and iOS devs to parse this content. Notes: I noticed some issues with the guide while making the original updates and made a few updates to fix the issues. This includes: - Strengthened the introduction. - Removed the 'recipe' wording (this isn't structured like our recipes nor in the recipe directory). - There were quite a few coding errors and grammatical flow problems in the original Firebase Test Lab section for Android. I've cleaned these up but I'm also not 100% certain that those commands are accurate today. We might want to follow up on that section and make sure the steps work. _Issues fixed by this PR (if any):_ _PRs or commits this PR depends on (if any):_ ## Presubmit checklist - [x] This PR is marked as draft with an explanation if not meant to land until a future stable release. - [x] This PR doesn’t contain automatically generated corrections (Grammarly or similar). - [x] This PR follows the [Google Developer Documentation Style Guidelines](https://developers.google.com/style) — for example, it doesn’t use _i.e._ or _e.g._, and it avoids _I_ and _we_ (first person). - [x] This PR uses [semantic line breaks](https://github.com/dart-lang/site-shared/blob/main/doc/writing-for-dart-and-flutter-websites.md#semantic-line-breaks) of 80 characters or fewer.
1 parent a8b3d5e commit b3f9e58

File tree

1 file changed

+124
-79
lines changed
  • src/content/testing/integration-tests

1 file changed

+124
-79
lines changed

src/content/testing/integration-tests/index.md

Lines changed: 124 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,24 @@ description: Learn how to write integration tests
55

66
<?code-excerpt path-base="testing/integration_tests/how_to"?>
77

8-
This recipe describes how to use the
9-
[`integration_test`][] package to run integration tests.
10-
The Flutter SDK includes the `integration_test` package.
11-
Integration tests using this package have the following
12-
properties.
8+
## Introduction
139

14-
* Use the `flutter drive` command to run tests
15-
on a physical device or emulator.
16-
* Run on [Firebase Test Lab][],
17-
to automate testing on a variety of devices.
18-
* Use [flutter_test][] APIs to enable tests to be written in a style similar to [widget tests][]
10+
This guide describes how to run integration tests with your Flutter app. With
11+
it, you'll learn how to do the following:
1912

20-
In this recipe, learn how to test a counter app.
13+
* Set up integration tests.
14+
* Verify if an app displays specific text.
15+
* Tap specific widgets.
16+
* Run integration tests.
2117

22-
* how to set up integration tests
23-
* how to verify if an app displays specific text
24-
* how to tap specific widgets
25-
* how to run integration tests
18+
The guide references the `counter_app` project that comes with
19+
Flutter and the Flutter [`integration_test`][] package. The
20+
`integration_test` package lets you:
2621

27-
This recipe uses the following steps:
28-
29-
1. Create an app to test.
30-
2. Add the `integration_test` dependency.
31-
3. Create the test files.
32-
4. Write the integration test.
33-
5. Run the integration test.
22+
* Use the `flutter drive` command to run tests on a physical device or emulator.
23+
* Run on [Firebase Test Lab][], to automate testing on a variety of devices.
24+
* Use [flutter_test][] APIs to write tests in a style similar to
25+
[widget tests][].
3426

3527
## Create a new app to test
3628

@@ -337,20 +329,49 @@ Based on platform, the command result should resemble the following output.
337329

338330
---
339331

340-
### Test on a mobile device
332+
### Test on an Android device
341333

342-
To test on a real iOS or Android device,
334+
To test on a real Android device,
343335
complete the following tasks.
344336

345-
1. Connect the device.
337+
1. Connect the Android device.
338+
339+
1. Run the following command from the root of the project.
340+
341+
```console
342+
$ flutter test integration_test/app_test.dart
343+
```
344+
345+
The result should resemble the following output.
346+
347+
```console
348+
$ flutter test integration_test/app_test.dart
349+
00:04 +0: loading /path/to/counter_app/integration_test/app_test.dart
350+
00:15 +0: loading /path/to/counter_app/integration_test/app_test.dart
351+
00:18 +0: loading /path/to/counter_app/integration_test/app_test.dart 2,387ms
352+
Installing build/app/outputs/flutter-apk/app.apk... 612ms
353+
00:21 +1: All tests passed!
354+
```
355+
356+
1. Verify that the test removed the Counter App when it finished.
357+
If not, subsequent tests fail. If needed, press on the app and choose
358+
**Remove App** from the context menu.
359+
360+
---
361+
362+
### Test on an iOS device
363+
364+
To test on a real iOS device, complete the following tasks.
365+
366+
1. Connect the iOS device.
346367

347368
1. Run the following command from the root of the project.
348369

349370
```console
350371
$ flutter test integration_test/app_test.dart
351372
```
352373

353-
The result should resemble the following output. This example uses iOS.
374+
The result should resemble the following output.
354375

355376
```console
356377
$ flutter test integration_test/app_test.dart
@@ -479,21 +500,15 @@ To learn more, see the
479500

480501
---
481502

482-
### Test using the Firebase Test Lab
503+
### Test in Firebase Test Lab (Android)
483504

484-
To test both Android and iOS targets,
485-
you can use the Firebase Test Lab.
505+
You can use Firebase Test Lab to test Android targets.
486506

487507
#### Android setup
488508

489509
Follow the instructions in the [Android Device Testing][]
490510
section of the README.
491511

492-
#### iOS setup
493-
494-
Follow the instructions in the [iOS Device Testing][]
495-
section of the README.
496-
497512
#### Test Lab project setup
498513

499514
1. Launch your [Firebase Console][].
@@ -506,71 +521,102 @@ section of the README.
506521

507522
#### Upload an Android APK
508523

509-
1. Create an APK using Gradle.
524+
Complete the following steps to upload an Android APK.
510525

511-
```console
512-
$ pushd android
513-
# flutter build generates files in android/ for building the app
514-
flutter build apk
515-
./gradlew app:assembleAndroidTest
516-
./gradlew app:assembleDebug -Ptarget=integration_test/<name>_test.dart
517-
$ popd
518-
```
526+
1. Create an APK using Gradle.
519527

520-
Where `<name>_test.dart` is the file created in the
521-
**Project Setup** section.
528+
```console
529+
// Go to the Android directory which contains the gradlew script
530+
$ pushd android
522531

523-
:::note
524-
To use `--dart-define` with `gradlew:
532+
// Build the APK for Flutter with gradlew
533+
$ flutter build apk
525534

526-
1. Encode all parameters with `base64`.
527-
1. Pass the parameters to gradle in a comma-separated list.
535+
// Build an Android test APK
536+
$ ./gradlew app:assembleAndroidTest
528537

529-
```console
530-
./gradlew project:task -Pdart-defines="{base64 (key=value)},[...]"
531-
```
538+
// Build a debug APK by passing in an integration test
539+
$ ./gradlew app:assembleDebug -Ptarget=integration_test/<name>_test.dart
540+
```
541+
542+
* `<name>_test.dart`: The file created in the **Project Setup** section.
532543

533-
:::
544+
1. If needed, pass parameters into the integration test as a comma-separated
545+
list. Encode all parameters as `base64`.
534546

535-
To start a Robo test and run other tests, drag the "debug" APK from
536-
`<flutter_project_directory>/build/app/outputs/apk/debug`
537-
into the **Android Robo Test** target on the web page.
547+
```console
548+
$ ./gradlew project:task --defines="{base64 (key=value)}[, ...]"
549+
```
538550

539-
<img src='/assets/images/docs/integration-test/test-lab-2.png' alt="Firebase Test Lab upload">
551+
* `(key=value)}[, ...]`: Replace this with a comma-separated list of
552+
key value pairs.
540553

541-
1. Click **Run a test**.
554+
1. Return to your previous directory.
542555

543-
1. Select the **Instrumentation** test type.
556+
```console
557+
$ popd
558+
```
544559

545-
1. Add the App APK to the **App APK or AAB** box.
560+
For additional instructions, see the
561+
[Firebase Test Lab section of the README][].
546562

547-
`<flutter_project_directory>/build/app/outputs/apk/debug/<file>.apk`
563+
#### Start Robo test
548564

549-
1. Add the Test APK to the **Test APK** box.
565+
To use Robo test to run integration tests, complete the following steps.
550566

551-
`<flutter_project_directory>/build/app/outputs/apk/androidTest/debug/<file>.apk`
567+
1. Drag the debug APK from
568+
`<flutter_project_directory>/build/app/outputs/apk/debug`
569+
into the **Android Robo Test** target on the web page. For example:
552570

553-
<img src='/assets/images/docs/integration-test/test-lab-3.png' alt="Firebase Test Lab upload two APKs">
571+
<img src='/assets/images/docs/integration-test/test-lab-2.png' alt="Firebase Test Lab upload">
554572

555-
If a failure occurs, click the red icon to view the output:
573+
1. Click **Run a test**.
556574

557-
<img src='/assets/images/docs/integration-test/test-lab-4.png' alt="Firebase Test Lab test results">
575+
1. Select the **Instrumentation** test type.
558576

559-
#### Upload an Android APK from the command line
577+
1. Add the App APK to the **App APK or AAB** box.
560578

561-
See the [Firebase Test Lab section of the README][]
562-
for instructions on uploading the APKs from the command line.
579+
`<flutter_project_directory>/build/app/outputs/apk/debug/<file>.apk`
563580

564-
#### Upload Xcode tests
581+
1. Add the Test APK to the **Test APK** box.
565582

566-
To learn how to upload the .zip file,
567-
consult the [Firebase TestLab iOS instructions][]
568-
on the Firebase TestLab section of the Firebase Console.
583+
`<flutter_project_directory>/build/app/outputs/apk/androidTest/debug/<file>.apk`
569584

570-
#### Upload Xcode tests from the command line
585+
<img src='/assets/images/docs/integration-test/test-lab-3.png' alt="Firebase Test Lab upload two APKs">
571586

572-
To learn how to upload the .zip file from the command line,
573-
consult the [iOS Device Testing][] section in the README.
587+
1. If a failure occurs, click the red icon to view the output:
588+
589+
<img src='/assets/images/docs/integration-test/test-lab-4.png' alt="Firebase Test Lab test results">
590+
591+
---
592+
593+
### Test in Firebase Test Lab (iOS)
594+
595+
You can use Firebase Test Lab to test iOS targets.
596+
597+
#### iOS setup
598+
599+
Follow the [iOS Device Testing instructions][].
600+
601+
#### Test Lab project setup
602+
603+
1. Launch your [Firebase Console][].
604+
605+
1. Create a new Firebase project if necessary.
606+
607+
1. Navigate to **Quality > Test Lab**.
608+
609+
<img src='/assets/images/docs/integration-test/test-lab-1.png' alt="Firebase Test Lab Console">
610+
611+
#### Upload Xcode tests through the Firebase Console
612+
613+
To learn how to upload tests from a ZIP file, using the
614+
Firebase Test Lab Console, consult the [Firebase Test Lab iOS instructions][].
615+
616+
#### Upload Xcode tests to Firebase Console with the command line
617+
618+
To learn how to upload tests from a ZIP file from the command line to the
619+
Firebase Test Lab Console, consult the [iOS Device Testing instructions][].
574620

575621
[`integration_test`]: {{site.repo.flutter}}/tree/main/packages/integration_test#integration_test
576622
[Android Device Testing]: {{site.repo.flutter}}/tree/main/packages/integration_test#android-device-testing
@@ -580,13 +626,12 @@ consult the [iOS Device Testing][] section in the README.
580626
[Firebase Console]: http://console.firebase.google.com/
581627
[Firebase Test Lab section of the README]: {{site.repo.flutter}}/tree/main/packages/integration_test#firebase-test-lab
582628
[Firebase Test Lab]: {{site.firebase}}/docs/test-lab
583-
[Firebase TestLab iOS instructions]: {{site.firebase}}/docs/test-lab/ios/firebase-console
629+
[Firebase Test Lab iOS instructions]: {{site.firebase}}/docs/test-lab/ios/firebase-console
584630
[flutter_test]: {{site.api}}/flutter/flutter_test/flutter_test-library.html
585631
[Integration testing]: /testing/integration-tests
586-
[iOS Device Testing]: {{site.repo.flutter}}/tree/main/packages/integration_test#ios-device-testing
632+
[iOS Device Testing instructions]: {{site.repo.flutter}}/tree/main/packages/integration_test#ios-device-testing
587633
[Running Flutter driver tests with web]: {{site.repo.flutter}}/blob/main/docs/contributing/testing/Running-Flutter-Driver-tests-with-Web.md
588634
[widget tests]: /testing/overview#widget-tests
589-
590635
[flutter_driver]: {{site.api}}/flutter/flutter_driver/flutter_driver-library.html
591636
[integration_test usage]: {{site.repo.flutter}}/tree/main/packages/integration_test#usage
592637
[samples]: {{site.repo.samples}}

0 commit comments

Comments
 (0)