-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[integration_test] Recommend tests to be in integration_test/, fix example
#2986
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,78 +7,91 @@ and native Android instrumentation testing. | |
| ## Usage | ||
|
|
||
| Add a dependency on the `integration_test` and `flutter_test` package in the | ||
| `dev_dependencies` section of pubspec.yaml. For plugins, do this in the | ||
| pubspec.yaml of the example app. | ||
| `dev_dependencies` section of `pubspec.yaml`. For plugins, do this in the | ||
| `pubspec.yaml` of the example app. | ||
|
|
||
| Invoke `IntegrationTestWidgetsFlutterBinding.ensureInitialized()` at the start | ||
| of a test file, e.g. | ||
| Create a `integration_test/` directory for your package. In this directory, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the cirrus file we are still using test_driver/ directory even though it is not the recommended directory?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh sorry, I just read the recommended package structure. Is there a reason for these recommendations? One idea that comes to my mind is: integration_test_driver.dart won't be the same for different tests.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It won't be the same but I would think for most use cases the bulk of the testing code should go into the test script that runs on the device, and the driver is mainly for reporting. Currently, some packages place the test scripts in
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We did the renaming like this last week in the for the web engine: flutter-team-archive/engine#20954 |
||
| create a `<name>_test.dart`, using the following as a starting point to make | ||
| assertions. | ||
|
|
||
| ```dart | ||
| import 'package:flutter_test/flutter_test.dart'; | ||
| import 'package:integration_test/integration_test.dart'; | ||
|
|
||
| void main() { | ||
| IntegrationTestWidgetsFlutterBinding.ensureInitialized(); | ||
|
|
||
| testWidgets("failing test example", (WidgetTester tester) async { | ||
| expect(2 + 2, equals(5)); | ||
| }); | ||
| } | ||
| ``` | ||
|
|
||
| ## Test locations | ||
|
|
||
| It is recommended to put integration_test tests in the `test/` folder of the app | ||
| or package. For example apps, if the integration_test test references example | ||
| app code, it should go in `example/test/`. It is also acceptable to put | ||
| integration_test tests in `test_driver/` folder so that they're alongside the | ||
| runner app (see below). | ||
|
|
||
| ## Using Flutter Driver to Run Tests | ||
|
|
||
| `IntegrationTestWidgetsTestBinding` supports launching the on-device tests with | ||
| `flutter drive`. Note that the tests don't use the `FlutterDriver` API, they | ||
| use `testWidgets` instead. | ||
| ### Driver Entrypoint | ||
|
|
||
| Put the a file named `<package_name>_integration_test.dart` in the app' | ||
| `test_driver` directory: | ||
| An accompanying driver script will be needed that can be shared across all | ||
| integration tests. Create a `integration_test_driver.dart` in the `test_driver/` | ||
| directory with the following contents: | ||
|
|
||
| ```dart | ||
| import 'dart:async'; | ||
|
|
||
| import 'package:integration_test/integration_test_driver.dart'; | ||
|
|
||
| Future<void> main() async => integrationDriver(); | ||
| Future<void> main() => integrationDriver(); | ||
| ``` | ||
|
|
||
| To run a example app test with Flutter driver: | ||
| ### Package Structure | ||
|
|
||
| Your package should have a structure that looks like this: | ||
|
|
||
| ```sh | ||
| cd example | ||
| flutter drive test/<package_name>_integration.dart | ||
| ``` | ||
| lib/ | ||
| ... | ||
| integration_test/ | ||
| foo_test.dart | ||
| bar_test.dart | ||
| test/ | ||
| # Other unit tests go here. | ||
| test_driver/ | ||
| integration_test_driver.dart | ||
| ``` | ||
|
|
||
| To test plugin APIs using Flutter driver: | ||
| [Example](https://github.com/flutter/plugins/tree/master/packages/integration_test/example) | ||
|
|
||
| ## Using Flutter Driver to Run Tests | ||
|
|
||
| These tests can be launched with the `flutter drive` command. | ||
|
|
||
| To run `integration_test/foo_test.dart`: | ||
|
|
||
| ```sh | ||
| cd example | ||
| flutter drive --driver=test_driver/<package_name>_test.dart test/<package_name>_integration_test.dart | ||
| flutter drive \ | ||
| --driver=test_driver/integration_test_driver.dart \ | ||
| --target=integration_test/foo_test.dart | ||
| ``` | ||
|
|
||
| You can run tests on web in release or profile mode. | ||
| ### Web | ||
|
|
||
| Make sure you have [enabled web support](https://flutter.dev/docs/get-started/web#set-up) | ||
| then [download and run](https://flutter.dev/docs/cookbook/testing/integration/introduction#6b-web) | ||
| the web driver in another process. | ||
|
|
||
| First you need to make sure you have downloaded the driver for the browser. | ||
| Use following command to execute the tests, passing either `--release` or | ||
| `--profile` as debug mode is not supported. | ||
|
jiahaog marked this conversation as resolved.
Outdated
|
||
|
|
||
| ```sh | ||
| cd example | ||
| flutter drive -v --target=test_driver/<package_name>dart -d web-server --release --browser-name=chrome | ||
| flutter drive \ | ||
| --driver=test_driver/integration_test_driver.dart \ | ||
| --target=integration_test/foo_test.dart \ | ||
| -d web-server \ | ||
| --release | ||
| ``` | ||
|
|
||
| ## Android device testing | ||
| ## 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. | ||
| this test file `MainActivityTest.java` or another name of your choice. | ||
|
|
||
| ```java | ||
| package com.example.myapp; | ||
|
|
@@ -96,7 +109,7 @@ public class MainActivityTest { | |
| ``` | ||
|
|
||
| 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 | ||
| uses androidx's version of `AndroidJUnitRunner` and has androidx libraries as a | ||
| dependency. | ||
|
|
||
| ```gradle | ||
|
|
@@ -160,7 +173,7 @@ 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 device testing | ||
| ## iOS Device Testing | ||
|
|
||
| You need to change `iOS/Podfile` to avoid test target statically linking to the plugins. One way is to | ||
| link all of the plugins dynamically: | ||
|
|
@@ -189,4 +202,4 @@ change the code. You can change `RunnerTests.m` to the name of your choice. | |
| INTEGRATION_TEST_IOS_RUNNER(RunnerTests) | ||
| ``` | ||
|
|
||
| Now you can start RunnerTests to kick out integration tests! | ||
| Now you can start RunnerTests to kick-off integration tests! | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| import 'package:integration_test/integration_test_driver.dart'; | ||
|
|
||
| Future<void> main() => integrationDriver(); |
Uh oh!
There was an error while loading. Please reload this page.