Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(256)

Side by Side Diff: README.md

Issue 1086213002: Support a @Timeout annotation. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: CHANGELOG + README Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « CHANGELOG.md ('k') | lib/pub_serve.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 271
272 stream.listen(expectAsync((number) { 272 stream.listen(expectAsync((number) {
273 expect(number, inInclusiveRange(1, 3)); 273 expect(number, inInclusiveRange(1, 3));
274 }, count: 3)); 274 }, count: 3));
275 }); 275 });
276 } 276 }
277 ``` 277 ```
278 278
279 [expectAsync]: http://www.dartdocs.org/documentation/test/latest/index.html#test /test@id_expectAsync 279 [expectAsync]: http://www.dartdocs.org/documentation/test/latest/index.html#test /test@id_expectAsync
280 280
281 ## Configuring Tests
282
283 ### Timeouts
284
285 By default, tests will time out after 30 seconds of inactivity. However, this
286 can be configured on a per-test, -group, or -suite basis. To change the timeout
287 for a test suite, put a `@Timeout` annotation at the top of the file:
288
289 ```dart
290 @Timeout(new Duration(seconds: 45))
291
292 import "package:test/test.dart";
293
294 void main() {
295 // ...
296 }
297 ```
298
299 In addition to setting an absolute timeout, you can set the timeout relative to
300 the default using `@Timeout.factor`. For example, `@Timeout.factor(1.5)` will
301 set the timeout to one and a half times as long as the default—45 seconds.
302
303 Timeouts can be set for tests and groups using the `timeout` parameter. This
304 parameter takes a `Timeout` object just like the annotation. For example:
305
306 ```dart
307 import "package:test/test.dart";
308
309 void main() {
310 group("slow tests", () {
311 // ...
312
313 test("even slower test", () {
314 // ...
315 }, timeout: new Timeout.factor(2))
316 }, timeout: new Timeout(new Duration(minutes: 1)));
317 }
318 ```
319
320 Nested timeouts apply in order from outermost to innermost. That means that
321 "even slower test" will take two minutes to time out, since it multiplies the
322 group's timeout by 2.
323
281 ## Testing With `barback` 324 ## Testing With `barback`
282 325
283 Packages using the `barback` transformer system may need to test code that's 326 Packages using the `barback` transformer system may need to test code that's
284 created or modified using transformers. The test runner handles this using the 327 created or modified using transformers. The test runner handles this using the
285 `--pub-serve` option, which tells it to load the test code from a `pub serve` 328 `--pub-serve` option, which tells it to load the test code from a `pub serve`
286 instance rather than from the filesystem. **This feature is only supported on 329 instance rather than from the filesystem. **This feature is only supported on
287 Dart `1.9.2` and higher.** 330 Dart `1.9.2` and higher.**
288 331
289 Before using the `--pub-serve` option, add the `test/pub_serve` transformer to 332 Before using the `--pub-serve` option, add the `test/pub_serve` transformer to
290 your `pubspec.yaml`. This transformer adds the necessary bootstrapping code that 333 your `pubspec.yaml`. This transformer adds the necessary bootstrapping code that
(...skipping 19 matching lines...) Expand all
310 353
311 In this case, the port is `8081`. In another terminal, pass this port to 354 In this case, the port is `8081`. In another terminal, pass this port to
312 `--pub-serve` and otherwise invoke `pub run test:test` as normal: 355 `--pub-serve` and otherwise invoke `pub run test:test` as normal:
313 356
314 ```shell 357 ```shell
315 $ pub run test:test --pub-serve=8081 -p chrome 358 $ pub run test:test --pub-serve=8081 -p chrome
316 "pub serve" is compiling test/my_app_test.dart... 359 "pub serve" is compiling test/my_app_test.dart...
317 "pub serve" is compiling test/utils_test.dart... 360 "pub serve" is compiling test/utils_test.dart...
318 00:00 +42: All tests passed! 361 00:00 +42: All tests passed!
319 ``` 362 ```
OLDNEW
« no previous file with comments | « CHANGELOG.md ('k') | lib/pub_serve.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698