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 |
11 ```dart | 11 ```dart |
12 import "package:test/test.dart"; | 12 import "package:test/test.dart"; |
13 | 13 |
14 void main() { | 14 void main() { |
15 test("String.split() splits the string on the delimiter", () { | 15 test("String.split() splits the string on the delimiter", () { |
16 var string = "foo,bar,baz"; | 16 var string = "foo,bar,baz"; |
17 expect(string.split(","), equals(["foo", "bar", "baz"])); | 17 expect(string.split(","), equals(["foo", "bar", "baz"])); |
18 }); | 18 }); |
19 | 19 |
20 test("String.trim() removes surrounding whitespace", () { | 20 test("String.trim() removes surrounding whitespace", () { |
21 var string = " foo "; | 21 var string = " foo "; |
22 expect(string.trim(), equals("foo")); | 22 expect(string.trim(), equals("foo")); |
23 }); | 23 }); |
24 } | 24 } |
25 ``` | 25 ``` |
26 | 26 |
27 Tests can be grouped together using the [`group()`] function. Each group's | 27 Tests can be grouped together using the [`group()`][group] function. Each |
28 description is added to the beginning of its test's descriptions. | 28 group's description is added to the beginning of its test's descriptions. |
| 29 |
| 30 [group]: http://www.dartdocs.org/documentation/test/latest/index.html#test/test@
id_group |
29 | 31 |
30 ```dart | 32 ```dart |
31 import "package:test/test.dart"; | 33 import "package:test/test.dart"; |
32 | 34 |
33 void main() { | 35 void main() { |
34 group("String", () { | 36 group("String", () { |
35 test(".split() splits the string on the delimiter", () { | 37 test(".split() splits the string on the delimiter", () { |
36 var string = "foo,bar,baz"; | 38 var string = "foo,bar,baz"; |
37 expect(string.split(","), equals(["foo", "bar", "baz"])); | 39 expect(string.split(","), equals(["foo", "bar", "baz"])); |
38 }); | 40 }); |
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 | 486 |
485 In this case, the port is `8081`. In another terminal, pass this port to | 487 In this case, the port is `8081`. In another terminal, pass this port to |
486 `--pub-serve` and otherwise invoke `pub run test:test` as normal: | 488 `--pub-serve` and otherwise invoke `pub run test:test` as normal: |
487 | 489 |
488 ```shell | 490 ```shell |
489 $ pub run test:test --pub-serve=8081 -p chrome | 491 $ pub run test:test --pub-serve=8081 -p chrome |
490 "pub serve" is compiling test/my_app_test.dart... | 492 "pub serve" is compiling test/my_app_test.dart... |
491 "pub serve" is compiling test/utils_test.dart... | 493 "pub serve" is compiling test/utils_test.dart... |
492 00:00 +42: All tests passed! | 494 00:00 +42: All tests passed! |
493 ``` | 495 ``` |
OLD | NEW |