|
2 | 2 | title: Testing Flutter apps |
3 | 3 | --- |
4 | 4 |
|
5 | | -The more features your app has, the harder it is to test it manually. A |
6 | | -good set of automated tests help you make sure your app performs |
| 5 | +The more features your app has, the harder it is to test manually. |
| 6 | +Automated tests help ensure that your app performs |
7 | 7 | correctly before you publish it, while retaining your feature and bug fix |
8 | 8 | velocity. |
9 | 9 |
|
10 | | -There are many kinds of automated testing. These are summarized below: |
| 10 | +Automated testing falls into a few categories: |
11 | 11 |
|
12 | 12 | - A _unit test_ tests a single function, method, or class. External dependencies |
13 | | - of the unit under test are generally mocked out using, for example, |
14 | | - [`package:mockito`](https://github.com/dart-lang/mockito). |
15 | | - Unit tests generally do not read from/write to disk, render to screen and do |
16 | | - not receive user actions from outside the process running the test. The goal |
| 13 | + of the unit under test are generally [mocked out](/cookbook/testing/mocking). |
| 14 | + Unit tests generally don't read from or write to disk, render to screen, |
| 15 | + or receive user actions from outside the process running the test. The goal |
17 | 16 | of a unit test is to verify the correctness of a unit of logic under a |
18 | 17 | variety of conditions. |
19 | 18 | - A _widget test_ (in other UI frameworks referred to as _component test_) tests |
@@ -41,19 +40,20 @@ different kinds of tests: |
41 | 40 | |----------------------|--------|--------|-------------| |
42 | 41 | | **Confidence** | Low | Higher | Highest | |
43 | 42 | | **Maintenance cost** | Low | Higher | Highest | |
44 | | -| **Dependencies** | Few | More | Lots | |
| 43 | +| **Dependencies** | Few | More | Most | |
45 | 44 | | **Execution speed** | Quick | Slower | Slowest | |
46 | 45 | {:.table.table-striped} |
47 | 46 |
|
48 | | -**Tip**: As a rule of thumb a well-tested app has a very high number of unit |
49 | | -and widget tests, tracked by [code coverage](https://en.wikipedia.org/wiki/Code_coverage), |
50 | | -and a good number of integration tests covering all the important usage |
51 | | -scenarios. |
| 47 | +{{site.alert.tip}} |
| 48 | + A well-tested app has many unit and widget tests, |
| 49 | + tracked by [code coverage](https://en.wikipedia.org/wiki/Code_coverage), |
| 50 | + plus enough integration tests to cover all the important use cases. |
| 51 | +{{site.alert.end}} |
52 | 52 |
|
53 | 53 |
|
54 | 54 | ## Unit testing |
55 | 55 |
|
56 | | -Some Flutter libraries, such as `dart:ui`, are not available in the standalone |
| 56 | +Some Flutter libraries, such as `dart:ui`, aren't available in the standalone |
57 | 57 | Dart VM that ships with the default Dart SDK. The `flutter test` command lets |
58 | 58 | you run your tests in a local Dart VM with a headless version of the Flutter |
59 | 59 | Engine, which supplies these libraries. Using this command you can run any test, |
@@ -87,15 +87,20 @@ dev_dependencies: |
87 | 87 | sdk: flutter |
88 | 88 | ``` |
89 | 89 |
|
90 | | -(This is needed even if your test does not itself explicitly import |
91 | | -`flutter_test`, because the test framework itself uses it behind the |
92 | | -scenes.) |
| 90 | +{{site.alert.note}} |
| 91 | + The dev dependency on `flutter_test` is required even if |
| 92 | + your test doesn't explicitly import `flutter_test`, |
| 93 | + because the test framework uses `flutter_test` behind the scenes. |
| 94 | +{{site.alert.end}} |
93 | 95 |
|
94 | 96 | To run the test, run `flutter test test/unit_test.dart` from your |
95 | 97 | project directory (not from the `test` subdirectory). |
96 | 98 |
|
97 | 99 | To run all your tests, run `flutter test` from your project directory. |
98 | 100 |
|
| 101 | +For information on how to create mock services, see |
| 102 | +[Mock dependencies using Mockito](/cookbook/testing/mocking). |
| 103 | + |
99 | 104 |
|
100 | 105 | ## Widget testing |
101 | 106 |
|
@@ -323,12 +328,11 @@ but for the `_test` suffix in it. |
323 | 328 |
|
324 | 329 | ## Continuous integration and testing |
325 | 330 |
|
326 | | -For information on continuous deployment and testing, see |
| 331 | +For information on continuous deployment and testing, see the following: |
327 | 332 |
|
328 | 333 | * [Continuous Delivery using fastlane with Flutter](/docs/deployment/fastlane-cd/) |
329 | 334 | * [Test Flutter apps on Travis](https://medium.com/flutter-io/test-flutter-apps-on-travis-3fd5142ecd8c) |
330 | | -* Test Flutter apps with [GitLab |
331 | | - CI](https://docs.gitlab.com/ee/ci/README.html#doc-nav). You'll |
332 | | - need to create and configure a `.gitlab-ci.yml` file. You can [find an |
| 335 | +* [GitLab Continuous Integration (GitLab CI/CD](https://docs.gitlab.com/ee/ci/README.html#doc-nav). |
| 336 | + You'll need to create and configure a `.gitlab-ci.yml` file. You can [find an |
333 | 337 | example](https://raw.githubusercontent.com/brianegan/flutter_redux/master/.gitlab-ci.yml) |
334 | 338 | in the [flutter_redux library](https://github.com/brianegan/flutter_redux). |
0 commit comments