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

Unified Diff: packages/unittest/test/with_test_environment_test.dart

Issue 1400473008: Roll Observatory packages and add a roll script (Closed) Base URL: git@github.com:dart-lang/observatory_pub_packages.git@master
Patch Set: Created 5 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « packages/unittest/test/throws_matchers_test.dart ('k') | packages/usage/.gitignore » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: packages/unittest/test/with_test_environment_test.dart
diff --git a/packages/unittest/test/with_test_environment_test.dart b/packages/unittest/test/with_test_environment_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..456384fa6f55ec9d4144b0e963a2025209c63013
--- /dev/null
+++ b/packages/unittest/test/with_test_environment_test.dart
@@ -0,0 +1,84 @@
+// 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';
+
+class TestConfiguration extends SimpleConfiguration {
+ final Completer _completer = new Completer();
+ List<TestCase> _results;
+
+ TestConfiguration();
+
+ void onSummary(int passed, int failed, int errors, List<TestCase> results,
+ String uncaughtError) {
+ super.onSummary(passed, failed, errors, results, uncaughtError);
+ _results = results;
+ }
+
+ Future get done => _completer.future;
+
+ onDone(success) {
+ new Future.sync(() => super.onDone(success))
+ .then(_completer.complete)
+ .catchError(_completer.completeError);
+ }
+
+ bool checkIfTestRan(String testName) {
+ return _results.any((test) => test.description == testName);
+ }
+}
+
+Future runUnittests(Function callback) {
+ TestConfiguration config = unittestConfiguration = new TestConfiguration();
+ callback();
+
+ return config.done;
+}
+
+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() {
+ // Check that setting config a second time does not change the configuration
+ runUnittests(runTests);
+ var config = unittestConfiguration;
+ runUnittests(runTests1);
+ expect(config, unittestConfiguration);
+
+ // Test that we can run both when encapsulating in their own private test
+ // environment. Also test that the tests actually running are the ones
+ // scheduled in the runTests/runTests1 methods.
+ withTestEnvironment(() {
+ runUnittests(runTests).whenComplete(() {
+ TestConfiguration config = unittestConfiguration;
+ expect(config.checkIfTestRan('test'), true);
+ expect(config.checkIfTestRan('test1'), false);
+ });
+ });
+ withTestEnvironment(() {
+ runUnittests(runTests1).whenComplete(() {
+ TestConfiguration config = unittestConfiguration;
+ expect(config.checkIfTestRan('test'), false);
+ expect(config.checkIfTestRan('test1'), true);
+ });
+ });
+
+ // Third test that we can run with two nested test environments.
+ withTestEnvironment(() {
+ runUnittests(runTests);
+ withTestEnvironment(() {
+ runUnittests(runTests1);
+ });
+ });
+}
« no previous file with comments | « packages/unittest/test/throws_matchers_test.dart ('k') | packages/usage/.gitignore » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698