@@ -5,32 +5,24 @@ description: Learn how to write integration tests
5
5
6
6
<? code-excerpt path-base="testing/integration_tests/how_to"?>
7
7
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
13
9
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:
19
12
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.
21
17
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:
26
21
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] [ ] .
34
26
35
27
## Create a new app to test
36
28
@@ -337,20 +329,49 @@ Based on platform, the command result should resemble the following output.
337
329
338
330
---
339
331
340
- ### Test on a mobile device
332
+ ### Test on an Android device
341
333
342
- To test on a real iOS or Android device,
334
+ To test on a real Android device,
343
335
complete the following tasks.
344
336
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.
346
367
347
368
1. Run the following command from the root of the project.
348
369
349
370
```console
350
371
$ flutter test integration_test/app_test.dart
351
372
```
352
373
353
- The result should resemble the following output. This example uses iOS.
374
+ The result should resemble the following output.
354
375
355
376
``` console
356
377
$ flutter test integration_test/app_test.dart
@@ -479,21 +500,15 @@ To learn more, see the
479
500
480
501
---
481
502
482
- ### Test using the Firebase Test Lab
503
+ ### Test in Firebase Test Lab (Android)
483
504
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.
486
506
487
507
#### Android setup
488
508
489
509
Follow the instructions in the [ Android Device Testing] [ ]
490
510
section of the README.
491
511
492
- #### iOS setup
493
-
494
- Follow the instructions in the [ iOS Device Testing] [ ]
495
- section of the README.
496
-
497
512
#### Test Lab project setup
498
513
499
514
1 . Launch your [ Firebase Console] [ ] .
@@ -506,71 +521,102 @@ section of the README.
506
521
507
522
#### Upload an Android APK
508
523
509
- 1 . Create an APK using Gradle .
524
+ Complete the following steps to upload an Android APK .
510
525
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.
519
527
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
522
531
523
- ::: note
524
- To use ` --dart-define ` with `gradlew:
532
+ // Build the APK for Flutter with gradlew
533
+ $ flutter build apk
525
534
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
528
537
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.
532
543
533
- :::
544
+ 1. If needed, pass parameters into the integration test as a comma-separated
545
+ list. Encode all parameters as `base64`.
534
546
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
+ ```
538
550
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.
540
553
541
- 1 . Click ** Run a test ** .
554
+ 1. Return to your previous directory .
542
555
543
- 1 . Select the ** Instrumentation** test type.
556
+ ```console
557
+ $ popd
558
+ ```
544
559
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][].
546
562
547
- ` <flutter_project_directory>/build/app/outputs/apk/debug/<file>.apk `
563
+ #### Start Robo test
548
564
549
- 1 . Add the Test APK to the ** Test APK ** box .
565
+ To use Robo test to run integration tests, complete the following steps .
550
566
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:
552
570
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">
554
572
555
- If a failure occurs, click the red icon to view the output:
573
+ 1. Click **Run a test**.
556
574
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.
558
576
559
- #### Upload an Android APK from the command line
577
+ 1. Add the App APK to the **App APK or AAB** box.
560
578
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`
563
580
564
- #### Upload Xcode tests
581
+ 1. Add the Test APK to the **Test APK** box.
565
582
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`
569
584
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">
571
586
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][].
574
620
575
621
[`integration_test`]: {{site.repo.flutter}}/tree/main/packages/integration_test#integration_test
576
622
[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.
580
626
[Firebase Console]: http://console.firebase.google.com/
581
627
[Firebase Test Lab section of the README]: {{site.repo.flutter}}/tree/main/packages/integration_test#firebase-test-lab
582
628
[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
584
630
[flutter_test]: {{site.api}}/flutter/flutter_test/flutter_test-library.html
585
631
[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
587
633
[Running Flutter driver tests with web]: {{site.repo.flutter}}/blob/main/docs/contributing/testing/Running-Flutter-Driver-tests-with-Web.md
588
634
[widget tests]: /testing/overview#widget-tests
589
-
590
635
[flutter_driver]: {{site.api}}/flutter/flutter_driver/flutter_driver-library.html
591
636
[integration_test usage]: {{site.repo.flutter}}/tree/main/packages/integration_test#usage
592
637
[samples]: {{site.repo.samples}}
0 commit comments