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 Selectors](#platform-selectors) | 6 * [Platform Selectors](#platform-selectors) |
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) |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 | 117 |
118 // ... | 118 // ... |
119 } | 119 } |
120 ``` | 120 ``` |
121 | 121 |
122 [setUp]: http://www.dartdocs.org/documentation/test/latest/index.html#test/test@
id_setUp | 122 [setUp]: http://www.dartdocs.org/documentation/test/latest/index.html#test/test@
id_setUp |
123 [tearDown]: http://www.dartdocs.org/documentation/test/latest/index.html#test/te
st@id_tearDown | 123 [tearDown]: http://www.dartdocs.org/documentation/test/latest/index.html#test/te
st@id_tearDown |
124 | 124 |
125 ## Running Tests | 125 ## Running Tests |
126 | 126 |
127 A single test file can be run just using `pub run test:test path/to/test.dart` | 127 A single test file can be run just using `pub run test path/to/test.dart`. |
128 (on Dart 1.10, this can be shortened to `pub run test path/to/test.dart`). | |
129 | 128 |
130  | 129  |
131 | 130 |
132 Many tests can be run at a time using `pub run test:test path/to/dir`. | 131 Many tests can be run at a time using `pub run test path/to/dir`. |
133 | 132 |
134  | 133  |
135 | 134 |
136 It's also possible to run a test on the Dart VM only by invoking it using `dart | 135 It's also possible to run a test on the Dart VM only by invoking it using `dart |
137 path/to/test.dart`, but this doesn't load the full test runner and will be | 136 path/to/test.dart`, but this doesn't load the full test runner and will be |
138 missing some features. | 137 missing some features. |
139 | 138 |
140 The test runner considers any file that ends with `_test.dart` to be a test | 139 The test runner considers any file that ends with `_test.dart` to be a test |
141 file. If you don't pass any paths, it will run all the test files in your | 140 file. If you don't pass any paths, it will run all the test files in your |
142 `test/` directory, making it easy to test your entire application at once. | 141 `test/` directory, making it easy to test your entire application at once. |
143 | 142 |
144 By default, tests are run in the Dart VM, but you can run them in the browser as | 143 By default, tests are run in the Dart VM, but you can run them in the browser as |
145 well by passing `pub run test:test -p chrome path/to/test.dart`. | 144 well by passing `pub run test -p chrome path/to/test.dart`. `test` will take |
146 `test` will take care of starting the browser and loading the tests, and all | 145 care of starting the browser and loading the tests, and all the results will be |
147 the results will be reported on the command line just like for VM tests. In | 146 reported on the command line just like for VM tests. In fact, you can even run |
148 fact, you can even run tests on both platforms with a single command: `pub run | 147 tests on both platforms with a single command: `pub run test -p "chrome,vm" |
149 test:test -p "chrome,vm" path/to/test.dart`. | 148 path/to/test.dart`. |
150 | 149 |
151 ### Restricting Tests to Certain Platforms | 150 ### Restricting Tests to Certain Platforms |
152 | 151 |
153 Some test files only make sense to run on particular platforms. They may use | 152 Some test files only make sense to run on particular platforms. They may use |
154 `dart:html` or `dart:io`, they might test Windows' particular filesystem | 153 `dart:html` or `dart:io`, they might test Windows' particular filesystem |
155 behavior, or they might use a feature that's only available in Chrome. The | 154 behavior, or they might use a feature that's only available in Chrome. The |
156 [`@TestOn`][TestOn] annotation makes it easy to declare exactly which platforms | 155 [`@TestOn`][TestOn] annotation makes it easy to declare exactly which platforms |
157 a test file should run on. Just put it at the top of your file, before any | 156 a test file should run on. Just put it at the top of your file, before any |
158 `library` or `import` declarations: | 157 `library` or `import` declarations: |
159 | 158 |
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
631 ```shell | 630 ```shell |
632 $ pub serve | 631 $ pub serve |
633 Loading source assets... | 632 Loading source assets... |
634 Loading test/pub_serve transformers... | 633 Loading test/pub_serve transformers... |
635 Serving my_app web on http://localhost:8080 | 634 Serving my_app web on http://localhost:8080 |
636 Serving my_app test on http://localhost:8081 | 635 Serving my_app test on http://localhost:8081 |
637 Build completed successfully | 636 Build completed successfully |
638 ``` | 637 ``` |
639 | 638 |
640 In this case, the port is `8081`. In another terminal, pass this port to | 639 In this case, the port is `8081`. In another terminal, pass this port to |
641 `--pub-serve` and otherwise invoke `pub run test:test` as normal: | 640 `--pub-serve` and otherwise invoke `pub run test` as normal: |
642 | 641 |
643 ```shell | 642 ```shell |
644 $ pub run test:test --pub-serve=8081 -p chrome | 643 $ pub run test --pub-serve=8081 -p chrome |
645 "pub serve" is compiling test/my_app_test.dart... | 644 "pub serve" is compiling test/my_app_test.dart... |
646 "pub serve" is compiling test/utils_test.dart... | 645 "pub serve" is compiling test/utils_test.dart... |
647 00:00 +42: All tests passed! | 646 00:00 +42: All tests passed! |
648 ``` | 647 ``` |
649 | 648 |
650 ## Further Reading | 649 ## Further Reading |
651 | 650 |
652 Check out the [API docs][api] for detailed information about all the functions | 651 Check out the [API docs][api] for detailed information about all the functions |
653 available to tests. | 652 available to tests. |
654 | 653 |
655 [api]: http://www.dartdocs.org/documentation/test/latest/index.html | 654 [api]: http://www.dartdocs.org/documentation/test/latest/index.html |
656 | 655 |
657 The test runner also supports a machine-readable JSON-based reporter. This | 656 The test runner also supports a machine-readable JSON-based reporter. This |
658 reporter allows the test runner to be wrapped and its progress presented in | 657 reporter allows the test runner to be wrapped and its progress presented in |
659 custom ways (for example, in an IDE). See [the protocol documentation][json] for | 658 custom ways (for example, in an IDE). See [the protocol documentation][json] for |
660 more details. | 659 more details. |
661 | 660 |
662 [json]: https://github.com/dart-lang/test/blob/master/doc/json_reporter.md | 661 [json]: https://github.com/dart-lang/test/blob/master/doc/json_reporter.md |
OLD | NEW |