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

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

Issue 12217142: Unit test improvements: (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 10 months 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
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 // TODO(gram): 5 // TODO(gram):
6 // Unfortunately I can't seem to test anything that involves timeouts, e.g. 6 // Unfortunately I can't seem to test anything that involves timeouts, e.g.
7 // insufficient callbacks, because the timeout is controlled externally 7 // insufficient callbacks, because the timeout is controlled externally
8 // (test.dart?), and we would need to use a shorter timeout for the inner tests 8 // (test.dart?), and we would need to use a shorter timeout for the inner tests
9 // so the outer timeout doesn't fire. So I removed all such tests. 9 // so the outer timeout doesn't fire. So I removed all such tests.
10 // I'd like to revisit this at some point. 10 // I'd like to revisit this at some point.
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 String uncaughtError) { 70 String uncaughtError) {
71 _result = buildStatusString(passed, failed, errors, results, 71 _result = buildStatusString(passed, failed, errors, results,
72 count: count, setup: setup, teardown: teardown, 72 count: count, setup: setup, teardown: teardown,
73 uncaughtError: uncaughtError); 73 uncaughtError: uncaughtError);
74 } 74 }
75 75
76 void onDone(bool success) { 76 void onDone(bool success) {
77 _port.send(_result); 77 _port.send(_result);
78 } 78 }
79 } 79 }
80
81 foo() {
82 ++_testconfig.count;
83 }
84
80 runTest() { 85 runTest() {
81 port.receive((testName, sendport) { 86 port.receive((testName, sendport) {
82 configure(_testconfig = new TestConfiguration(sendport)); 87 configure(_testconfig = new TestConfiguration(sendport));
83 if (testName == 'single correct test') { 88 if (testName == 'single correct test') {
84 test(testName, () => expect(2 + 3, equals(5))); 89 test(testName, () => expect(2 + 3, equals(5)));
85 } else if (testName == 'single failing test') { 90 } else if (testName == 'single failing test') {
86 test(testName, () => expect(2 + 2, equals(5))); 91 test(testName, () => expect(2 + 2, equals(5)));
87 } else if (testName == 'exception test') { 92 } else if (testName == 'exception test') {
88 test(testName, () { throw new Exception('Fail.'); }); 93 test(testName, () { throw new Exception('Fail.'); });
89 } else if (testName == 'group name test') { 94 } else if (testName == 'group name test') {
(...skipping 15 matching lines...) Expand all
105 }); 110 });
106 } else if (testName == 'setup and teardown test') { 111 } else if (testName == 'setup and teardown test') {
107 group('a', () { 112 group('a', () {
108 setUp(() { _testconfig.setup = 'setup'; }); 113 setUp(() { _testconfig.setup = 'setup'; });
109 tearDown(() { _testconfig.teardown = 'teardown'; }); 114 tearDown(() { _testconfig.teardown = 'teardown'; });
110 test(testName, () {}); 115 test(testName, () {});
111 }); 116 });
112 } else if (testName == 'correct callback test') { 117 } else if (testName == 'correct callback test') {
113 test(testName, 118 test(testName,
114 () =>_defer(expectAsync0((){ ++_testconfig.count;}))); 119 () =>_defer(expectAsync0((){ ++_testconfig.count;})));
115 } else if (testName == 'excess callback test') { 120 } else if (testName == 'excess callback test with callback name') {
116 test(testName, () { 121 test(testName, () {
117 var _callback = expectAsync0((){ ++_testconfig.count;}); 122 var _callback = expectAsync0(foo);
118 _defer(_callback); 123 _defer(_callback);
119 _defer(_callback); 124 _defer(_callback);
120 }); 125 });
121 } else if (testName == 'completion test') { 126 } else if (testName == 'completion test') {
122 test(testName, () { 127 test(testName, () {
123 var _callback; 128 var _callback;
124 _callback = expectAsyncUntil0(() { 129 _callback = expectAsyncUntil0(() {
125 if (++_testconfig.count < 10) { 130 if (++_testconfig.count < 10) {
126 _defer(_callback); 131 _defer(_callback);
127 } 132 }
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 main() { 259 main() {
255 tests = [ 260 tests = [
256 'single correct test', 261 'single correct test',
257 'single failing test', 262 'single failing test',
258 'exception test', 263 'exception test',
259 'group name test', 264 'group name test',
260 'setup test', 265 'setup test',
261 'teardown test', 266 'teardown test',
262 'setup and teardown test', 267 'setup and teardown test',
263 'correct callback test', 268 'correct callback test',
264 'excess callback test', 269 'excess callback test with callback name',
265 'completion test', 270 'completion test',
266 'async exception test', 271 'async exception test',
267 'late exception test', 272 'late exception test',
268 'middle exception test', 273 'middle exception test',
269 'async setup/teardown test' 274 'async setup/teardown test'
270 ]; 275 ];
271 276
272 expected = [ 277 expected = [
273 buildStatusString(1, 0, 0, tests[0]), 278 buildStatusString(1, 0, 0, tests[0]),
274 buildStatusString(0, 1, 0, tests[1], 279 buildStatusString(0, 1, 0, tests[1],
275 message: 'Expected: <5> but: was <4>.'), 280 message: 'Expected: <5> but: was <4>.'),
276 buildStatusString(0, 1, 0, tests[2], message: 'Caught Exception: Fail.'), 281 buildStatusString(0, 1, 0, tests[2], message: 'Caught Exception: Fail.'),
277 buildStatusString(2, 0, 0, 'a a::a b b'), 282 buildStatusString(2, 0, 0, 'a a::a b b'),
278 buildStatusString(1, 0, 0, 'a ${tests[4]}', count: 0, setup: 'setup'), 283 buildStatusString(1, 0, 0, 'a ${tests[4]}', count: 0, setup: 'setup'),
279 buildStatusString(1, 0, 0, 'a ${tests[5]}', count: 0, setup: '', 284 buildStatusString(1, 0, 0, 'a ${tests[5]}', count: 0, setup: '',
280 teardown: 'teardown'), 285 teardown: 'teardown'),
281 buildStatusString(1, 0, 0, 'a ${tests[6]}', count: 0, 286 buildStatusString(1, 0, 0, 'a ${tests[6]}', count: 0,
282 setup: 'setup', teardown: 'teardown'), 287 setup: 'setup', teardown: 'teardown'),
283 buildStatusString(1, 0, 0, tests[7], count: 1), 288 buildStatusString(1, 0, 0, tests[7], count: 1),
284 buildStatusString(0, 0, 1, tests[8], count: 1, 289 buildStatusString(0, 0, 1, tests[8], count: 1,
285 message: 'Callback called more times than expected (2 > 1).'), 290 message: 'Callback foo called more times than expected (2 > 1).'),
286 buildStatusString(1, 0, 0, tests[9], count: 10), 291 buildStatusString(1, 0, 0, tests[9], count: 10),
287 buildStatusString(0, 1, 0, tests[10], message: 'Caught error!'), 292 buildStatusString(0, 1, 0, tests[10], message: 'Caught error!'),
288 buildStatusString(1, 0, 1, 'testOne', 293 buildStatusString(1, 0, 1, 'testOne',
289 message: 'Callback called after already being marked as done ' 294 message: 'Callback called after already being marked as done '
290 '(1).:testTwo:'), 295 '(1).:testTwo:'),
291 buildStatusString(2, 1, 0, 296 buildStatusString(2, 1, 0,
292 'testOne::testTwo:Expected: false but: was <true>.:testThree'), 297 'testOne::testTwo:Expected: false but: was <true>.:testThree'),
293 buildStatusString(2, 0, 3, 298 buildStatusString(2, 0, 3,
294 'good setup/good teardown foo1::' 299 'good setup/good teardown foo1::'
295 'good setup/bad teardown foo2:good setup/bad teardown ' 300 'good setup/bad teardown foo2:good setup/bad teardown '
296 'foo2: Test teardown failed: Failed to complete tearDown:' 301 'foo2: Test teardown failed: Failed to complete tearDown:'
297 'bad setup/good teardown foo3:bad setup/good teardown ' 302 'bad setup/good teardown foo3:bad setup/good teardown '
298 'foo3: Test setup failed: Failed to complete setUp:' 303 'foo3: Test setup failed: Failed to complete setUp:'
299 'bad setup/bad teardown foo4:bad setup/bad teardown ' 304 'bad setup/bad teardown foo4:bad setup/bad teardown '
300 'foo4: Test teardown failed: Failed to complete tearDown:' 305 'foo4: Test teardown failed: Failed to complete tearDown:'
301 'post groups') 306 'post groups')
302 ]; 307 ];
303 308
304 actual = []; 309 actual = [];
305 310
306 nextTest(0); 311 nextTest(0);
307 } 312 }
308 313
OLDNEW
« pkg/unittest/lib/src/expect.dart ('K') | « pkg/unittest/test/matchers_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698