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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/unittest/lib/unittest.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/unittest/test/with_test_environment_test.dart
diff --git a/pkg/unittest/test/with_test_environment_test.dart b/pkg/unittest/test/with_test_environment_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..28792a49ab1742f77da075d0711cd64bfbfd6a60
--- /dev/null
+++ b/pkg/unittest/test/with_test_environment_test.dart
@@ -0,0 +1,60 @@
+// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library unittest.with_test_environment_test;
+
+import 'dart:async';
+import 'package:unittest/unittest.dart';
+
+Future runUnittests(Function callback) {
+ var config = new UnittestConfiguration();
+
+ unittestConfiguration = config;
+ callback();
+
+ 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.
+}
+
+class UnittestConfiguration extends SimpleConfiguration {
+ final Completer _completer = new Completer();
+
+ Future get done => _completer.future;
+
+ onDone(success) {
+ new Future.sync(() {
+ super.onDone(success);
+ }).then((_) => _completer.complete(_))
+ .catchError((error, stack) => _completer.completeError(error, stack));
+ }
+}
+
+void runTests() {
+ test('test', () => expect(2 + 3, equals(5)));
+}
+
+void runTests1() {
+ test('test1', () => expect(4 + 3, equals(7)));
+}
+
+// Test that we can run two different sets of tests in the same run using the
+// withTestEnvironment method.
+void main() {
+ // First check that we cannot call runUnittests twice in a row without it
+ // throwing a StateError due to the unittestConfiguration being set globally
+ // in the first call.
+ try {
+ runUnittests(runTests);
+ runUnittests(runTests1);
+ throw 'Expected this to be unreachable since 2nd run above should throw';
+ } catch(error) {
+ if (error is! StateError)
+ throw error;
+ // expected, silently ignore.
+ }
+
+ // Second test that we can run both when encapsulating in their own private
+ // test environment.
+ withTestEnvironment(() => runUnittests(runTests));
+ 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.
+}
« 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