Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(111)

Side by Side Diff: pkg/unittest/unittest.dart

Issue 11229063: Fixed unittest documentation to use new import syntax. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 /** 5 /**
6 * A library for writing dart unit tests. 6 * A library for writing dart unit tests.
7 * 7 *
8 * To import this library, specify the relative path to 8 * To import this library, use the pub package manager.
9 * pkg/unittest/unittest.dart. 9 * Create a pubspec.yaml file in your project and add
10 * a dependancies for unittest with the following lines:
Bob Nystrom 2012/10/23 18:08:55 "dependancies for" -> "dependency on"
butlermatt 2012/10/23 19:50:30 Done.
11 * name: my_app
Bob Nystrom 2012/10/23 18:08:55 You can probably omit this line.
butlermatt 2012/10/23 19:50:30 Done.
12 * dependancies:
Bob Nystrom 2012/10/23 18:08:55 "dependancies" -> "dependencies"
butlermatt 2012/10/23 19:50:30 Done.
13 * unittest:
14 * sdk: unittest
15 *
16 * Then run 'pub install' from your project directory or using
17 * the DartEditor
Bob Nystrom 2012/10/23 18:08:55 Add a ".".
butlermatt 2012/10/23 19:50:30 Done.
18 *
19 * Please see [Pub Getting Started](http://pub.dartlang.org/doc)
20 * for more details about the pub package manager.
10 * 21 *
11 * ##Concepts## 22 * ##Concepts##
12 * 23 *
13 * * Tests: Tests are specified via the top-level function [test], they can be 24 * * Tests: Tests are specified via the top-level function [test], they can be
14 * organized together using [group]. 25 * organized together using [group].
15 * * Checks: Test expectations can be specified via [expect] 26 * * Checks: Test expectations can be specified via [expect]
16 * * Matchers: [expect] assertions are written declaratively using [Matcher]s 27 * * Matchers: [expect] assertions are written declaratively using [Matcher]s
17 * * Configuration: The framework can be adapted by calling [configure] with a 28 * * Configuration: The framework can be adapted by calling [configure] with a
18 * [Configuration]. Common configurations can be found in this package 29 * [Configuration]. Common configurations can be found in this package
19 * under: 'dom\_config.dart' (deprecated), 'html\_config.dart' (for running 30 * under: 'dom\_config.dart' (deprecated), 'html\_config.dart' (for running
20 * tests compiled to Javascript in a browser), and 'vm\_config.dart' (for 31 * tests compiled to Javascript in a browser), and 'vm\_config.dart' (for
21 * running native Dart tests on the VM). 32 * running native Dart tests on the VM).
22 * 33 *
23 * ##Examples## 34 * ##Examples##
24 * 35 *
25 * A trivial test: 36 * A trivial test:
26 * 37 *
27 * #import('path-to-dart/pkg/unittest/unitest.dart'); 38 * import 'package:unittest/unitest.dart';
Bob Nystrom 2012/10/23 18:08:55 Not related to your change, but we might as well f
butlermatt 2012/10/23 19:50:30 Done.
28 * main() { 39 * main() {
29 * test('this is a test', () { 40 * test('this is a test', () {
30 * int x = 2 + 3; 41 * int x = 2 + 3;
31 * expect(x, equals(5)); 42 * expect(x, equals(5));
32 * }); 43 * });
33 * } 44 * }
34 * 45 *
35 * Multiple tests: 46 * Multiple tests:
36 * 47 *
37 * #import('path-to-dart/pkg/unittest/unitest.dart'); 48 * import 'package:unittest/unitest.dart';
38 * main() { 49 * main() {
39 * test('this is a test', () { 50 * test('this is a test', () {
40 * int x = 2 + 3; 51 * int x = 2 + 3;
41 * expect(x, equals(5)); 52 * expect(x, equals(5));
42 * }); 53 * });
43 * test('this is another test', () { 54 * test('this is another test', () {
44 * int x = 2 + 3; 55 * int x = 2 + 3;
45 * expect(x, equals(5)); 56 * expect(x, equals(5));
46 * }); 57 * });
47 * } 58 * }
48 * 59 *
49 * Multiple tests, grouped by category: 60 * Multiple tests, grouped by category:
50 * 61 *
51 * #import('path-to-dart/pkg/unittest/unitest.dart'); 62 * import 'package:unittest/unitest.dart';
52 * main() { 63 * main() {
53 * group('group A', () { 64 * group('group A', () {
54 * test('test A.1', () { 65 * test('test A.1', () {
55 * int x = 2 + 3; 66 * int x = 2 + 3;
56 * expect(x, equals(5)); 67 * expect(x, equals(5));
57 * }); 68 * });
58 * test('test A.2', () { 69 * test('test A.2', () {
59 * int x = 2 + 3; 70 * int x = 2 + 3;
60 * expect(x, equals(5)); 71 * expect(x, equals(5));
61 * }); 72 * });
62 * }); 73 * });
63 * group('group B', () { 74 * group('group B', () {
64 * test('this B.1', () { 75 * test('this B.1', () {
65 * int x = 2 + 3; 76 * int x = 2 + 3;
66 * expect(x, equals(5)); 77 * expect(x, equals(5));
67 * }); 78 * });
68 * }); 79 * });
69 * } 80 * }
70 * 81 *
71 * Asynchronous tests: if callbacks expect between 0 and 2 positional arguments, 82 * Asynchronous tests: if callbacks expect between 0 and 2 positional arguments,
72 * depending on the suffix of expectAsyncX(). expectAsyncX() will wrap a 83 * depending on the suffix of expectAsyncX(). expectAsyncX() will wrap a
73 * function into a new callback and will not consider the test complete until 84 * function into a new callback and will not consider the test complete until
74 * that callback is run. A count argument can be provided to specify the number 85 * that callback is run. A count argument can be provided to specify the number
75 * of times the callback should be called (the default is 1). 86 * of times the callback should be called (the default is 1).
76 * 87 *
77 * #import('path-to-dart/pkg/unittest/unitest.dart'); 88 * import 'package:unittest/unitest.dart';
78 * #import('dart:html'); 89 * import 'dart:html';
Bob Nystrom 2012/10/23 18:08:55 How about changing this to import 'dart:isolate' a
butlermatt 2012/10/23 19:50:30 Done.
79 * main() { 90 * main() {
80 * test('calllback is executed once', () { 91 * test('calllback is executed once', () {
81 * // wrap the callback of an asynchronous call with [expectAsync0] if 92 * // wrap the callback of an asynchronous call with [expectAsync0] if
82 * // the callback takes 0 arguments... 93 * // the callback takes 0 arguments...
83 * window.setTimeout(expectAsync0(() { 94 * window.setTimeout(expectAsync0(() {
84 * int x = 2 + 3; 95 * int x = 2 + 3;
85 * expect(x, equals(5)); 96 * expect(x, equals(5));
86 * }), 0); 97 * }), 0);
87 * }); 98 * });
88 * 99 *
(...skipping 19 matching lines...) Expand all
108 * depending on the number of positional arguments of the callback. In the 119 * depending on the number of positional arguments of the callback. In the
109 * future, we plan to expose a single `expectAsync` function that can be used 120 * future, we plan to expose a single `expectAsync` function that can be used
110 * regardless of the number of positional arguments. This requires new langauge 121 * regardless of the number of positional arguments. This requires new langauge
111 * features or fixes to the current spec (e.g. see 122 * features or fixes to the current spec (e.g. see
112 * [Issue 2706](http://dartbug.com/2706)). 123 * [Issue 2706](http://dartbug.com/2706)).
113 * 124 *
114 * Meanwhile, we plan to add this alternative API for callbacks of more than 2 125 * Meanwhile, we plan to add this alternative API for callbacks of more than 2
115 * arguments or that take named parameters. (this is not implemented yet, 126 * arguments or that take named parameters. (this is not implemented yet,
116 * but will be coming here soon). 127 * but will be coming here soon).
117 * 128 *
118 * #import('path-to-dart/pkg/unittest/unitest.dart'); 129 * import 'path-to-dart/pkg/unittest/unitest.dart';
119 * #import('dart:html'); 130 * import 'dart:html';
120 * main() { 131 * main() {
121 * test('calllback is executed', () { 132 * test('calllback is executed', () {
122 * // indicate ahead of time that an async callback is expected. 133 * // indicate ahead of time that an async callback is expected.
123 * var async = startAsync(); 134 * var async = startAsync();
124 * window.setTimeout(() { 135 * window.setTimeout(() {
125 * // Guard the body of the callback, so errors are propagated 136 * // Guard the body of the callback, so errors are propagated
126 * // correctly 137 * // correctly
127 * guardAsync(() { 138 * guardAsync(() {
128 * int x = 2 + 3; 139 * int x = 2 + 3;
129 * expect(x, equals(5)); 140 * expect(x, equals(5));
(...skipping 756 matching lines...) Expand 10 before | Expand all | Expand 10 after
886 } 897 }
887 898
888 /** Enable a test by ID. */ 899 /** Enable a test by ID. */
889 void enableTest(int testId) => _setTestEnabledState(testId, true); 900 void enableTest(int testId) => _setTestEnabledState(testId, true);
890 901
891 /** Disable a test by ID. */ 902 /** Disable a test by ID. */
892 void disableTest(int testId) => _setTestEnabledState(testId, false); 903 void disableTest(int testId) => _setTestEnabledState(testId, false);
893 904
894 /** Signature for a test function. */ 905 /** Signature for a test function. */
895 typedef void TestFunction(); 906 typedef void TestFunction();
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698