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) { | |
kevmoo
2014/11/11 21:27:53
Please use follow the convention of other unittest
wibling
2014/11/12 10:33:46
I am not sure how I should do that?
I am currentl
| |
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 } catch(error) { | |
33 if (error is! StateError) | |
34 throw error; | |
35 // expected, silently ignore. | |
36 } | |
37 | |
38 // Second test that we can run both when encapsulating in their own private | |
39 // test environment. | |
40 withTestEnvironment(() => runUnittests(runTests)); | |
41 withTestEnvironment(() => runUnittests(runTests1)); | |
42 | |
43 // Third test that we can run with two nested test environments. | |
44 withTestEnvironment(() { | |
45 runUnittests(runTests); | |
46 withTestEnvironment(() { | |
47 runUnittests(runTests1); | |
48 }); | |
49 }); | |
50 } | |
OLD | NEW |