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

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

Issue 709903004: Enhance the Dart unittest library to support multiple invocations in the same application run. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: make TestEnvironment private Created 6 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 | « pkg/unittest/lib/unittest.dart ('k') | 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
(Empty)
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
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.
4
5 library unittest.with_test_environment_test;
6
7 import 'dart:async';
8 import 'package:unittest/unittest.dart';
9
10 Future runUnittests(Function callback) {
11 var config = new UnittestConfiguration();
12
13 unittestConfiguration = config;
14 callback();
15
16 return config.done;
kustermann 2014/11/11 16:46:24 You never use the returned future as far as I can
wibling 2014/11/11 16:57:53 Done.
17 }
18
19 class UnittestConfiguration extends SimpleConfiguration {
20 final Completer _completer = new Completer();
21
22 Future get done => _completer.future;
23
24 onDone(success) {
25 new Future.sync(() {
26 super.onDone(success);
27 }).then((_) => _completer.complete(_))
28 .catchError((error, stack) => _completer.completeError(error, stack));
29 }
30 }
31
32 void runTests() {
33 test('test', () => expect(2 + 3, equals(5)));
34 }
35
36 void runTests1() {
37 test('test1', () => expect(4 + 3, equals(7)));
38 }
39
40 // Test that we can run two different sets of tests in the same run using the
41 // withTestEnvironment method.
42 void main() {
43 // First check that we cannot call runUnittests twice in a row without it
44 // throwing a StateError due to the unittestConfiguration being set globally
45 // in the first call.
46 try {
47 runUnittests(runTests);
48 runUnittests(runTests1);
49 throw 'Expected this to be unreachable since 2nd run above should throw';
50 } catch(error) {
51 if (error is! StateError)
52 throw error;
53 // expected, silently ignore.
54 }
55
56 // Second test that we can run both when encapsulating in their own private
57 // test environment.
58 withTestEnvironment(() => runUnittests(runTests));
59 withTestEnvironment(() => runUnittests(runTests1));
kustermann 2014/11/11 16:46:24 You could add a nested test as well withTestEnvir
wibling 2014/11/11 16:57:53 Done.
60 }
OLDNEW
« no previous file with comments | « pkg/unittest/lib/unittest.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698