@@ -7,78 +7,95 @@ and native Android instrumentation testing.
7
7
## Usage
8
8
9
9
Add a dependency on the ` integration_test ` and ` flutter_test ` package in the
10
- ` dev_dependencies ` section of pubspec.yaml. For plugins, do this in the
11
- pubspec.yaml of the example app.
10
+ ` dev_dependencies ` section of ` pubspec.yaml ` . For plugins, do this in the
11
+ ` pubspec.yaml ` of the example app.
12
12
13
- Invoke ` IntegrationTestWidgetsFlutterBinding.ensureInitialized() ` at the start
14
- of a test file, e.g.
13
+ Create a ` integration_test/ ` directory for your package. In this directory,
14
+ create a ` <name>_test.dart ` , using the following as a starting point to make
15
+ assertions.
15
16
16
17
``` dart
17
18
import 'package:flutter_test/flutter_test.dart';
18
19
import 'package:integration_test/integration_test.dart';
19
20
20
21
void main() {
21
22
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
23
+
22
24
testWidgets("failing test example", (WidgetTester tester) async {
23
25
expect(2 + 2, equals(5));
24
26
});
25
27
}
26
28
```
27
29
28
- ## Test locations
30
+ ### Driver Entrypoint
29
31
30
- It is recommended to put integration_test tests in the ` test/ ` folder of the app
31
- or package. For example apps, if the integration_test test references example
32
- app code, it should go in ` example/test/ ` . It is also acceptable to put
33
- integration_test tests in ` test_driver/ ` folder so that they're alongside the
34
- runner app (see below).
32
+ An accompanying driver script will be needed that can be shared across all
33
+ integration tests. Create a ` integration_test_driver.dart ` in the ` test_driver/ `
34
+ directory with the following contents:
35
35
36
- ## Using Flutter Driver to Run Tests
36
+ ``` dart
37
+ import 'package:integration_test/integration_test_driver.dart';
37
38
38
- ` IntegrationTestWidgetsTestBinding ` supports launching the on-device tests with
39
- ` flutter drive ` . Note that the tests don't use the ` FlutterDriver ` API, they
40
- use ` testWidgets ` instead.
39
+ Future<void> main() => integrationDriver();
40
+ ```
41
41
42
- Put the a file named ` <package_name>_integration_test.dart ` in the app'
43
- ` test_driver ` directory:
42
+ You can also use different driver scripts to customize the behavior of the app
43
+ under test. For example, ` FlutterDriver ` can also be parameterized with
44
+ different [ options] ( https://api.flutter.dev/flutter/flutter_driver/FlutterDriver/connect.html ) .
45
+ See the [ extended driver] ( https://github.com/flutter/plugins/tree/master/packages/integration_test/example/test_driver/integration_test_extended_driver.dart ) for an example.
44
46
45
- ``` dart
46
- import 'dart:async';
47
+ ### Package Structure
47
48
48
- import ' package:integration_test/integration_test_driver.dart';
49
+ Your package should have a structure that looks like this:
49
50
50
- Future<void> main() async => integrationDriver();
51
+ ```
52
+ lib/
53
+ ...
54
+ integration_test/
55
+ foo_test.dart
56
+ bar_test.dart
57
+ test/
58
+ # Other unit tests go here.
59
+ test_driver/
60
+ integration_test_driver.dart
51
61
```
52
62
53
- To run a example app test with Flutter driver:
63
+ [ Example ] ( https://github.com/flutter/plugins/tree/master/packages/integration_test/example )
54
64
55
- ``` sh
56
- cd example
57
- flutter drive test/< package_name> _integration.dart
58
- ```
65
+ ## Using Flutter Driver to Run Tests
66
+
67
+ These tests can be launched with the ` flutter drive ` command.
59
68
60
- To test plugin APIs using Flutter driver:
69
+ To run the ` integration_test/foo_test.dart ` test with the
70
+ ` test_driver/integration_test_driver.dart ` driver, use the following command:
61
71
62
72
``` sh
63
- cd example
64
- flutter drive --driver=test_driver/< package_name> _test.dart test/< package_name> _integration_test.dart
73
+ flutter drive \
74
+ --driver=test_driver/integration_test_driver.dart \
75
+ --target=integration_test/foo_test.dart
65
76
```
66
77
67
- You can run tests on web in release or profile mode.
78
+ ### Web
79
+
80
+ Make sure you have [ enabled web support] ( https://flutter.dev/docs/get-started/web#set-up )
81
+ then [ download and run] ( https://flutter.dev/docs/cookbook/testing/integration/introduction#6b-web )
82
+ the web driver in another process.
68
83
69
- First you need to make sure you have downloaded the driver for the browser.
84
+ Use following command to execute the tests:
70
85
71
86
``` sh
72
- cd example
73
- flutter drive -v --target=test_driver/< package_name> dart -d web-server --release --browser-name=chrome
87
+ flutter drive \
88
+ --driver=test_driver/integration_test_driver.dart \
89
+ --target=integration_test/foo_test.dart \
90
+ -d web-server
74
91
```
75
92
76
- ## Android device testing
93
+ ## Android Device Testing
77
94
78
95
Create an instrumentation test file in your application's
79
96
** android/app/src/androidTest/java/com/example/myapp/** directory (replacing
80
97
com, example, and myapp with values from your app's package name). You can name
81
- this test file MainActivityTest.java or another name of your choice.
98
+ this test file ` MainActivityTest.java ` or another name of your choice.
82
99
83
100
``` java
84
101
package com.example.myapp ;
@@ -96,7 +113,7 @@ public class MainActivityTest {
96
113
```
97
114
98
115
Update your application's ** myapp/android/app/build.gradle** to make sure it
99
- uses androidx's version of AndroidJUnitRunner and has androidx libraries as a
116
+ uses androidx's version of ` AndroidJUnitRunner ` and has androidx libraries as a
100
117
dependency.
101
118
102
119
``` gradle
@@ -160,7 +177,7 @@ You can pass additional parameters on the command line, such as the
160
177
devices you want to test on. See
161
178
[ gcloud firebase test android run] ( https://cloud.google.com/sdk/gcloud/reference/firebase/test/android/run ) .
162
179
163
- ## iOS device testing
180
+ ## iOS Device Testing
164
181
165
182
You need to change ` iOS/Podfile ` to avoid test target statically linking to the plugins. One way is to
166
183
link all of the plugins dynamically:
@@ -189,4 +206,4 @@ change the code. You can change `RunnerTests.m` to the name of your choice.
189
206
INTEGRATION_TEST_IOS_RUNNER (RunnerTests)
190
207
```
191
208
192
- Now you can start RunnerTests to kick out integration tests!
209
+ Now you can start RunnerTests to kick-off integration tests!
0 commit comments