OLD | NEW |
(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 'package:unittest/unittest.dart'; |
| 8 |
| 9 void runUnittests(Function callback) { |
| 10 unittestConfiguration = new SimpleConfiguration(); |
| 11 callback(); |
| 12 } |
| 13 |
| 14 void runTests() { |
| 15 test('test', () => expect(2 + 3, equals(5))); |
| 16 } |
| 17 |
| 18 void runTests1() { |
| 19 test('test1', () => expect(4 + 3, equals(7))); |
| 20 } |
| 21 |
| 22 // Test that we can run two different sets of tests in the same run using the |
| 23 // withTestEnvironment method. |
| 24 void main() { |
| 25 // First check that we cannot call runUnittests twice in a row without it |
| 26 // throwing a StateError due to the unittestConfiguration being set globally |
| 27 // in the first call. |
| 28 try { |
| 29 runUnittests(runTests); |
| 30 runUnittests(runTests1); |
| 31 throw 'Expected this to be unreachable since 2nd run above should throw'; |
| 32 } on StateError catch (error) { |
| 33 // expected, silently ignore. |
| 34 } |
| 35 |
| 36 // Second test that we can run both when encapsulating in their own private |
| 37 // test environment. |
| 38 withTestEnvironment(() => runUnittests(runTests)); |
| 39 withTestEnvironment(() => runUnittests(runTests1)); |
| 40 |
| 41 // Third test that we can run with two nested test environments. |
| 42 withTestEnvironment(() { |
| 43 runUnittests(runTests); |
| 44 withTestEnvironment(() { |
| 45 runUnittests(runTests1); |
| 46 }); |
| 47 }); |
| 48 } |
OLD | NEW |