OLD | NEW |
1 `test` provides a standard way of writing and running tests in Dart. | 1 `test` provides a standard way of writing and running tests in Dart. |
2 | 2 |
3 ## Writing Tests | 3 ## Writing Tests |
4 | 4 |
5 Tests are specified using the top-level [`test()`][test] function, and test | 5 Tests are specified using the top-level [`test()`][test] function, and test |
6 assertions are made using [`expect()`][expect]: | 6 assertions are made using [`expect()`][expect]: |
7 | 7 |
8 [test]: http://www.dartdocs.org/documentation/test/latest/index.html#test/test@i
d_test | 8 [test]: http://www.dartdocs.org/documentation/test/latest/index.html#test/test@i
d_test |
9 [expect]: http://www.dartdocs.org/documentation/test/latest/index.html#test/test
@id_expect | 9 [expect]: http://www.dartdocs.org/documentation/test/latest/index.html#test/test
@id_expect |
10 | 10 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 Platform selectors can contain identifiers, parentheses, and operators. When | 129 Platform selectors can contain identifiers, parentheses, and operators. When |
130 loading a test, each identifier is set to `true` or `false` based on the current | 130 loading a test, each identifier is set to `true` or `false` based on the current |
131 platform, and the test is only loaded if the platform selector returns `true`. | 131 platform, and the test is only loaded if the platform selector returns `true`. |
132 The operators `||`, `&&`, `!`, and `? :` all work just like they do in Dart. The | 132 The operators `||`, `&&`, `!`, and `? :` all work just like they do in Dart. The |
133 valid identifiers are: | 133 valid identifiers are: |
134 | 134 |
135 * `vm`: Whether the test is running on the command-line Dart VM. | 135 * `vm`: Whether the test is running on the command-line Dart VM. |
136 | 136 |
137 * `dartium`: Whether the test is running on Dartium. | 137 * `dartium`: Whether the test is running on Dartium. |
138 | 138 |
| 139 * `content-shell`: Whether the test is running on the headless Dartium content |
| 140 shell. |
| 141 |
139 * `chrome`: Whether the test is running on Google Chrome. | 142 * `chrome`: Whether the test is running on Google Chrome. |
140 | 143 |
141 * `dart-vm`: Whether the test is running on the Dart VM in any context, | 144 * `dart-vm`: Whether the test is running on the Dart VM in any context, |
142 including Dartium. It's identical to `!js`. | 145 including Dartium. It's identical to `!js`. |
143 | 146 |
144 * `browser`: Whether the test is running in any browser. | 147 * `browser`: Whether the test is running in any browser. |
145 | 148 |
146 * `js`: Whether the test has been compiled to JS. This is identical to | 149 * `js`: Whether the test has been compiled to JS. This is identical to |
147 `!dart-vm`. | 150 `!dart-vm`. |
148 | 151 |
(...skipping 16 matching lines...) Expand all Loading... |
165 * `posix`: Whether the test is running on a POSIX operating system. This is | 168 * `posix`: Whether the test is running on a POSIX operating system. This is |
166 equivalent to `!windows`. | 169 equivalent to `!windows`. |
167 | 170 |
168 For example, if you wanted to run a test on every browser but Chrome, you would | 171 For example, if you wanted to run a test on every browser but Chrome, you would |
169 write `@TestOn("browser && !chrome")`. | 172 write `@TestOn("browser && !chrome")`. |
170 | 173 |
171 ### Running Tests on Dartium | 174 ### Running Tests on Dartium |
172 | 175 |
173 Tests can be run on [Dartium][] by passing the `-p dartium` flag. If you're | 176 Tests can be run on [Dartium][] by passing the `-p dartium` flag. If you're |
174 using the Dart Editor, the test runner will be able to find Dartium | 177 using the Dart Editor, the test runner will be able to find Dartium |
175 automatically. However, since it usually isn't installed on a system-wide basis, | 178 automatically. On Mac OS, you can also [install it using Homebrew][homebrew]. |
176 the test runner may not otherwise be able to find the Dartium executable. To use | 179 Otherwise, make sure there's an executable called `dartium` (on Mac OS or Linux) |
177 it without the Editor, make sure there's an executable called `dartium` (on Mac | 180 or `dartium.exe` (on Windows) on your system path. |
178 OS or Linux) or `dartium.exe` (on Windows) on your system path. | |
179 | 181 |
180 [Dartium]: https://www.dartlang.org/tools/dartium/ | 182 [Dartium]: https://www.dartlang.org/tools/dartium/ |
| 183 [homebrew]: https://github.com/dart-lang/homebrew-dart |
| 184 |
| 185 Similarly, tests can be run on the headless Dartium content shell by passing `-p |
| 186 content-shell`. The content shell is installed along with Dartium when using |
| 187 Homebrew. Otherwise, you can downloaded it manually [from this |
| 188 page][content_shell]; if you do, make sure the executable named `content_shell` |
| 189 (on Mac OS or Linux) or `content_shell.exe` (on Windows) is on your system path. |
| 190 |
| 191 [content_shell]: http://gsdview.appspot.com/dart-archive/channels/stable/release
/latest/dartium/ |
181 | 192 |
182 [In the future][issue 63], there will be a more explicit way to configure the | 193 [In the future][issue 63], there will be a more explicit way to configure the |
183 location of the executable. | 194 location of both the Dartium and content shell executables. |
184 | 195 |
185 [issue 63]: https://github.com/dart-lang/test/issues/63 | 196 [issue 63]: https://github.com/dart-lang/test/issues/63 |
186 | 197 |
187 ## Asynchronous Tests | 198 ## Asynchronous Tests |
188 | 199 |
189 Tests written with `async`/`await` will work automatically. The test runner | 200 Tests written with `async`/`await` will work automatically. The test runner |
190 won't consider the test finished until the returned `Future` completes. | 201 won't consider the test finished until the returned `Future` completes. |
191 | 202 |
192 ```dart | 203 ```dart |
193 import "dart:async"; | 204 import "dart:async"; |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 | 307 |
297 In this case, the port is `8081`. In another terminal, pass this port to | 308 In this case, the port is `8081`. In another terminal, pass this port to |
298 `--pub-serve` and otherwise invoke `pub run test:test` as normal: | 309 `--pub-serve` and otherwise invoke `pub run test:test` as normal: |
299 | 310 |
300 ```shell | 311 ```shell |
301 $ pub run test:test --pub-serve=8081 -p chrome | 312 $ pub run test:test --pub-serve=8081 -p chrome |
302 "pub serve" is compiling test/my_app_test.dart... | 313 "pub serve" is compiling test/my_app_test.dart... |
303 "pub serve" is compiling test/utils_test.dart... | 314 "pub serve" is compiling test/utils_test.dart... |
304 00:00 +42: All tests passed! | 315 00:00 +42: All tests passed! |
305 ``` | 316 ``` |
OLD | NEW |