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 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 instance rather than from the filesystem. **This feature is only supported on | 448 instance rather than from the filesystem. **This feature is only supported on |
449 Dart `1.9.2` and higher.** | 449 Dart `1.9.2` and higher.** |
450 | 450 |
451 Before using the `--pub-serve` option, add the `test/pub_serve` transformer to | 451 Before using the `--pub-serve` option, add the `test/pub_serve` transformer to |
452 your `pubspec.yaml`. This transformer adds the necessary bootstrapping code that | 452 your `pubspec.yaml`. This transformer adds the necessary bootstrapping code that |
453 allows the test runner to load your tests properly: | 453 allows the test runner to load your tests properly: |
454 | 454 |
455 ```yaml | 455 ```yaml |
456 transformers: | 456 transformers: |
457 - test/pub_serve: | 457 - test/pub_serve: |
458 $include: test/**_test.dart | 458 $include: test/**_test{.*,}.dart |
| 459 ``` |
| 460 |
| 461 Note that if you're using the test runner along with [`polymer`][polymer], you |
| 462 have to make sure that the `test/pub_serve` transformer comes *after* the |
| 463 `polymer` transformer: |
| 464 |
| 465 [polymer]: https://www.dartlang.org/polymer/ |
| 466 |
| 467 ```yaml |
| 468 transformer: |
| 469 - polymer |
| 470 - test/pub_serve: |
| 471 $include: test/**_test{.*,}.dart |
459 ``` | 472 ``` |
460 | 473 |
461 Then, start up `pub serve`. Make sure to pay attention to which port it's using | 474 Then, start up `pub serve`. Make sure to pay attention to which port it's using |
462 to serve your `test/` directory: | 475 to serve your `test/` directory: |
463 | 476 |
464 ```shell | 477 ```shell |
465 $ pub serve | 478 $ pub serve |
466 Loading source assets... | 479 Loading source assets... |
467 Loading test/pub_serve transformers... | 480 Loading test/pub_serve transformers... |
468 Serving my_app web on http://localhost:8080 | 481 Serving my_app web on http://localhost:8080 |
469 Serving my_app test on http://localhost:8081 | 482 Serving my_app test on http://localhost:8081 |
470 Build completed successfully | 483 Build completed successfully |
471 ``` | 484 ``` |
472 | 485 |
473 In this case, the port is `8081`. In another terminal, pass this port to | 486 In this case, the port is `8081`. In another terminal, pass this port to |
474 `--pub-serve` and otherwise invoke `pub run test:test` as normal: | 487 `--pub-serve` and otherwise invoke `pub run test:test` as normal: |
475 | 488 |
476 ```shell | 489 ```shell |
477 $ pub run test:test --pub-serve=8081 -p chrome | 490 $ pub run test:test --pub-serve=8081 -p chrome |
478 "pub serve" is compiling test/my_app_test.dart... | 491 "pub serve" is compiling test/my_app_test.dart... |
479 "pub serve" is compiling test/utils_test.dart... | 492 "pub serve" is compiling test/utils_test.dart... |
480 00:00 +42: All tests passed! | 493 00:00 +42: All tests passed! |
481 ``` | 494 ``` |
OLD | NEW |