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

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

Issue 734343002: Fix bug in the unittest's withTestEnvironment package and apply more feedback from nweiz. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: review feedback 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/pubspec.yaml ('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
index 581261ad3993363cdce26217292707c070b27e2c..6f484af820d491f6ad0f4666ff5e8c568aeeb5e1 100644
--- a/pkg/unittest/test/with_test_environment_test.dart
+++ b/pkg/unittest/test/with_test_environment_test.dart
@@ -4,11 +4,46 @@
library unittest.with_test_environment_test;
+import 'dart:async';
import 'package:unittest/unittest.dart';
-void runUnittests(Function callback) {
- unittestConfiguration = new SimpleConfiguration();
+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((error, stack) => _completer.completeError(error, stack));
nweiz 2014/11/19 21:44:18 Indent this +4 spaces. You can write .then(_compl
wibling 2014/11/20 14:34:51 Done.
+ }
+
+ bool checkIfTestRan(String testName) {
+ for (final t in _results) {
nweiz 2014/11/19 21:44:18 We don't use "final" for local variables. Also, t
wibling 2014/11/20 14:34:51 Done.
+ if (t.description == testName) {
+ return true;
+ }
+ }
+ return false;
+ }
+}
+
+Future runUnittests(Function callback) {
+ var config = new TestConfiguration();
+ unittestConfiguration = config;
callback();
+
+ return config.done;
}
void runTests() {
@@ -33,10 +68,23 @@ void main() {
// expected, silently ignore.
}
- // Second test that we can run both when encapsulating in their own private
- // test environment.
- withTestEnvironment(() => runUnittests(runTests));
- withTestEnvironment(() => runUnittests(runTests1));
+ // 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(() {
« no previous file with comments | « pkg/unittest/pubspec.yaml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698