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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 | 91 |
92 The test runner considers any file that ends with `_test.dart` to be a test | 92 The test runner considers any file that ends with `_test.dart` to be a test |
93 file. If you don't pass any paths, it will run all the test files in your | 93 file. If you don't pass any paths, it will run all the test files in your |
94 `test/` directory, making it easy to test your entire application at once. | 94 `test/` directory, making it easy to test your entire application at once. |
95 | 95 |
96 By default, tests are run in the Dart VM, but you can run them in the browser as | 96 By default, tests are run in the Dart VM, but you can run them in the browser as |
97 well by passing `pub run test:test -p chrome path/to/test.dart`. | 97 well by passing `pub run test:test -p chrome path/to/test.dart`. |
98 `test` will take care of starting the browser and loading the tests, and all | 98 `test` will take care of starting the browser and loading the tests, and all |
99 the results will be reported on the command line just like for VM tests. In | 99 the results will be reported on the command line just like for VM tests. In |
100 fact, you can even run tests on both platforms with a single command: `pub run | 100 fact, you can even run tests on both platforms with a single command: `pub run |
101 test:test -p chrome,vm path/to/test.dart`. | 101 test:test -p "chrome,vm" path/to/test.dart`. |
102 | 102 |
103 ### Restricting Tests to Certain Platforms | 103 ### Restricting Tests to Certain Platforms |
104 | 104 |
105 Some test files only make sense to run on particular platforms. They may use | 105 Some test files only make sense to run on particular platforms. They may use |
106 `dart:html` or `dart:io`, they might test Windows' particular filesystem | 106 `dart:html` or `dart:io`, they might test Windows' particular filesystem |
107 behavior, or they might use a feature that's only available in Chrome. The | 107 behavior, or they might use a feature that's only available in Chrome. The |
108 [`@TestOn`][TestOn] annotation makes it easy to declare exactly which platforms | 108 [`@TestOn`][TestOn] annotation makes it easy to declare exactly which platforms |
109 a test file should run on. Just put it at the top of your file, before any | 109 a test file should run on. Just put it at the top of your file, before any |
110 `library` or `import` declarations: | 110 `library` or `import` declarations: |
111 | 111 |
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 | 485 |
486 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 |
487 `--pub-serve` and otherwise invoke `pub run test:test` as normal: | 487 `--pub-serve` and otherwise invoke `pub run test:test` as normal: |
488 | 488 |
489 ```shell | 489 ```shell |
490 $ pub run test:test --pub-serve=8081 -p chrome | 490 $ pub run test:test --pub-serve=8081 -p chrome |
491 "pub serve" is compiling test/my_app_test.dart... | 491 "pub serve" is compiling test/my_app_test.dart... |
492 "pub serve" is compiling test/utils_test.dart... | 492 "pub serve" is compiling test/utils_test.dart... |
493 00:00 +42: All tests passed! | 493 00:00 +42: All tests passed! |
494 ``` | 494 ``` |
OLD | NEW |