OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011, 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 /** | |
6 * testcase.dart: this file is sourced by unittest.dart. It defines [TestCase] | |
7 * and assumes unittest defines the type [TestFunction]. | |
8 */ | |
9 | |
10 /** Summarizes information about a single test case. */ | |
11 class TestCase { | |
12 /** Identifier for this test. */ | |
13 final int id; | |
14 | |
15 /** A description of what the test is specifying. */ | |
16 final String description; | |
17 | |
18 /** The setup function to call before the test, if any. */ | |
19 Function _setUp; | |
20 | |
21 Function get setUp() => _setUp; | |
22 set setUp(Function value) => _setUp = value; | |
23 | |
24 /** The teardown function to call after the test, if any. */ | |
25 Function _tearDown; | |
26 | |
27 Function get tearDown() => _tearDown; | |
28 set tearDown(Function value) => _tearDown = value; | |
29 | |
30 /** The body of the test case. */ | |
31 TestFunction test; | |
32 | |
33 /** | |
34 * Remaining number of callbacks functions that must reach a 'done' state | |
35 * to wait for before the test completes. | |
36 */ | |
37 int callbackFunctionsOutstanding; | |
38 | |
39 /** Error or failure message. */ | |
40 String message = ''; | |
41 | |
42 /** | |
43 * One of [_PASS], [_FAIL], [_ERROR], or [null] if the test hasn't run yet. | |
44 */ | |
45 String result; | |
46 | |
47 /** Stack trace associated with this test, or null if it succeeded. */ | |
48 String stackTrace; | |
49 | |
50 /** The group (or groups) under which this test is running. */ | |
51 final String currentGroup; | |
52 | |
53 Date startTime; | |
54 | |
55 Duration runningTime; | |
56 | |
57 bool enabled = true; | |
58 | |
59 bool _doneTeardown; | |
60 | |
61 TestCase(this.id, this.description, this.test, | |
62 this.callbackFunctionsOutstanding) | |
63 : currentGroup = _currentGroup, | |
64 _setUp = _testSetup, | |
65 _tearDown = _testTeardown; | |
66 | |
67 bool get isComplete() => !enabled || result != null; | |
68 | |
69 void run() { | |
70 if (enabled) { | |
71 result = stackTrace = null; | |
72 message = ''; | |
73 _doneTeardown = false; | |
74 if (_setUp != null) { | |
75 _setUp(); | |
76 } | |
77 _config.onTestStart(this); | |
78 test(); | |
79 } | |
80 } | |
81 | |
82 void _complete() { | |
83 if (!_doneTeardown) { | |
84 if (_tearDown != null) { | |
85 _tearDown(); | |
86 } | |
87 _doneTeardown = true; | |
88 } | |
89 _config.onTestResult(this); | |
90 } | |
91 | |
92 void pass() { | |
93 result = _PASS; | |
94 _complete(); | |
95 } | |
96 | |
97 void fail(String messageText, String stack) { | |
98 result = _FAIL; | |
99 message = messageText; | |
100 stackTrace = stack; | |
101 _complete(); | |
102 } | |
103 | |
104 void error(String messageText, String stack) { | |
105 result = _ERROR; | |
106 message = messageText; | |
107 stackTrace = stack; | |
108 _complete(); | |
109 } | |
110 } | |
OLD | NEW |