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](#writing-tests) | 3 * [Writing Tests](#writing-tests) |
4 * [Running Tests](#running-tests) | 4 * [Running Tests](#running-tests) |
5 * [Restricting Tests to Certain Platforms](#restricting-tests-to-certain-platf
orms) | 5 * [Restricting Tests to Certain Platforms](#restricting-tests-to-certain-platf
orms) |
6 * [Platform Selector Syntax](#platform-selector-syntax) | 6 * [Platform Selector Syntax](#platform-selector-syntax) |
7 * [Running Tests on Dartium](#running-tests-on-dartium) | 7 * [Running Tests on Dartium](#running-tests-on-dartium) |
8 * [Asynchronous Tests](#asynchronous-tests) | 8 * [Asynchronous Tests](#asynchronous-tests) |
9 * [Running Tests With Custom HTML](#running-tests-with-custom-html) | 9 * [Running Tests With Custom HTML](#running-tests-with-custom-html) |
10 * [Configuring Tests](#configuring-tests) | 10 * [Configuring Tests](#configuring-tests) |
11 * [Skipping Tests](#skipping-tests) | 11 * [Skipping Tests](#skipping-tests) |
12 * [Timeouts](#timeouts) | 12 * [Timeouts](#timeouts) |
13 * [Platform-Specific Configuration](#platform-specific-configuration) | 13 * [Platform-Specific Configuration](#platform-specific-configuration) |
14 * [Whole-Package Configuration](#whole-package-configuration) | 14 * [Whole-Package Configuration](#whole-package-configuration) |
| 15 * [Tagging Tests](#tagging-tests) |
15 * [Debugging](#debugging) | 16 * [Debugging](#debugging) |
16 * [Testing with `barback`](#testing-with-barback) | 17 * [Testing with `barback`](#testing-with-barback) |
17 * [Further Reading](#further-reading) | 18 * [Further Reading](#further-reading) |
18 | 19 |
19 ## Writing Tests | 20 ## Writing Tests |
20 | 21 |
21 Tests are specified using the top-level [`test()`][test] function, and test | 22 Tests are specified using the top-level [`test()`][test] function, and test |
22 assertions are made using [`expect()`][expect]: | 23 assertions are made using [`expect()`][expect]: |
23 | 24 |
24 [test]: http://www.dartdocs.org/documentation/test/latest/index.html#test/test@i
d_test | 25 [test]: http://www.dartdocs.org/documentation/test/latest/index.html#test/test@i
d_test |
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 Both the annotation and the parameter take a map. The map's keys are [platform | 481 Both the annotation and the parameter take a map. The map's keys are [platform |
481 selectors](#platform-selector-syntax) which describe the platforms for which the | 482 selectors](#platform-selector-syntax) which describe the platforms for which the |
482 specialized configuration applies. Its values are instances of some of the same | 483 specialized configuration applies. Its values are instances of some of the same |
483 annotation classes that can be used for a suite: `Skip` and `Timeout`. A value | 484 annotation classes that can be used for a suite: `Skip` and `Timeout`. A value |
484 can also be a list of these values. | 485 can also be a list of these values. |
485 | 486 |
486 If multiple platforms match, the configuration is applied in order from first to | 487 If multiple platforms match, the configuration is applied in order from first to |
487 last, just as they would in nested groups. This means that for configuration | 488 last, just as they would in nested groups. This means that for configuration |
488 like duration-based timeouts, the last matching value wins. | 489 like duration-based timeouts, the last matching value wins. |
489 | 490 |
| 491 ### Tagging Tests |
| 492 |
| 493 Tags are short strings that you can associate with tests, groups, and suites. |
| 494 They don't have any built-in meaning, but they're very useful nonetheless: you |
| 495 can associate your own custom configuration with them, or you can use them to |
| 496 easily filter tests so you only run the ones you need to. |
| 497 |
| 498 Tags are defined using the `@Tags` annotation for suites and the `tags` named |
| 499 parameter to `test()` and `group()`. For example: |
| 500 |
| 501 ```dart |
| 502 @Tags(["browser"]) |
| 503 |
| 504 import "package:test/test.dart"; |
| 505 |
| 506 void main() { |
| 507 test("successfully launches Chrome", () { |
| 508 // ... |
| 509 }, tags: "chrome"); |
| 510 |
| 511 test("launches two browsers at once", () { |
| 512 // ... |
| 513 }, tags: ["chrome", "firefox"]); |
| 514 } |
| 515 ``` |
| 516 |
| 517 If the test runner encounters a tag that wasn't declared in the |
| 518 [package configuration file][configuring tags], it'll print a warning, so be |
| 519 sure to include all your tags there. You can also use the file to provide |
| 520 default configuration for tags, like giving all `browser` tests twice as much |
| 521 time before they time out. |
| 522 |
| 523 [configuring tags]: https://github.com/dart-lang/test/blob/master/doc/package_co
nfig.md#configuring-tags |
| 524 |
| 525 Tests can be filtered based on their tags by passing command line flags. The |
| 526 `--tags` or `-t` flag will cause the test runner to only run tests with the |
| 527 given tags, and the `--exclude-tags` or `-x` flag will cause it to only run |
| 528 tests *without* the given tags. |
| 529 |
| 530 Note that tags must be valid Dart identifiers, although they may also contain |
| 531 hyphens. |
| 532 |
490 ### Whole-Package Configuration | 533 ### Whole-Package Configuration |
491 | 534 |
492 For configuration that applies across multiple files, or even the entire | 535 For configuration that applies across multiple files, or even the entire |
493 package, `test` supports a configuration file called `dart_test.yaml`. At its | 536 package, `test` supports a configuration file called `dart_test.yaml`. At its |
494 simplest, this file can contain the same sort of configuration that can be | 537 simplest, this file can contain the same sort of configuration that can be |
495 passed as command-line arguments: | 538 passed as command-line arguments: |
496 | 539 |
497 ```yaml | 540 ```yaml |
498 # This package's tests are very slow. Double the default timeout. | 541 # This package's tests are very slow. Double the default timeout. |
499 timeout: 2x | 542 timeout: 2x |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
591 available to tests. | 634 available to tests. |
592 | 635 |
593 [api]: http://www.dartdocs.org/documentation/test/latest/index.html | 636 [api]: http://www.dartdocs.org/documentation/test/latest/index.html |
594 | 637 |
595 The test runner also supports a machine-readable JSON-based reporter. This | 638 The test runner also supports a machine-readable JSON-based reporter. This |
596 reporter allows the test runner to be wrapped and its progress presented in | 639 reporter allows the test runner to be wrapped and its progress presented in |
597 custom ways (for example, in an IDE). See [the protocol documentation][json] for | 640 custom ways (for example, in an IDE). See [the protocol documentation][json] for |
598 more details. | 641 more details. |
599 | 642 |
600 [json]: https://github.com/dart-lang/test/blob/master/doc/json_reporter.md | 643 [json]: https://github.com/dart-lang/test/blob/master/doc/json_reporter.md |
OLD | NEW |