| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * testcase.dart: this file is sourced by unittest.dart. It defines [TestCase] | 6 * testcase.dart: this file is sourced by unittest.dart. It defines [TestCase] |
| 7 * and assumes unittest defines the type [TestFunction]. | 7 * and assumes unittest defines the type [TestFunction]. |
| 8 */ | 8 */ |
| 9 | 9 |
| 10 | |
| 11 /** Summarizes information about a single test case. */ | 10 /** Summarizes information about a single test case. */ |
| 12 class TestCase { | 11 class TestCase { |
| 13 /** Identifier for this test. */ | 12 /** Identifier for this test. */ |
| 14 final int id; | 13 final int id; |
| 15 | 14 |
| 16 /** A description of what the test is specifying. */ | 15 /** A description of what the test is specifying. */ |
| 17 final String description; | 16 final String description; |
| 18 | 17 |
| 18 /** The setup function to call before the test, if any. */ |
| 19 final _setup; |
| 20 |
| 21 /** The teardown function to call after the test, if any. */ |
| 22 final _teardown; |
| 23 |
| 19 /** The body of the test case. */ | 24 /** The body of the test case. */ |
| 20 final TestFunction test; | 25 final TestFunction test; |
| 21 | 26 |
| 22 /** Total number of callbacks to wait for before the test completes. */ | 27 /** Total number of callbacks to wait for before the test completes. */ |
| 23 int callbacks; | 28 int callbacks; |
| 24 | 29 |
| 25 /** Error or failure message. */ | 30 /** Error or failure message. */ |
| 26 String message = ''; | 31 String message = ''; |
| 27 | 32 |
| 28 /** | 33 /** |
| 29 * One of [_PASS], [_FAIL], or [_ERROR] or [null] if the test hasn't run yet. | 34 * One of [_PASS], [_FAIL], or [_ERROR] or [null] if the test hasn't run yet. |
| 30 */ | 35 */ |
| 31 String result; | 36 String result; |
| 32 | 37 |
| 33 /** Stack trace associated with this test, or null if it succeeded. */ | 38 /** Stack trace associated with this test, or null if it succeeded. */ |
| 34 String stackTrace; | 39 String stackTrace; |
| 35 | 40 |
| 36 /** The group (or groups) under which this test is running. */ | 41 /** The group (or groups) under which this test is running. */ |
| 37 final String currentGroup; | 42 final String currentGroup; |
| 38 | 43 |
| 39 Date startTime; | 44 Date startTime; |
| 40 | 45 |
| 41 Duration runningTime; | 46 Duration runningTime; |
| 42 | 47 |
| 43 TestCase(this.id, this.description, this.test, this.callbacks) | 48 TestCase(this.id, this.description, this.test, this.callbacks) |
| 44 : currentGroup = _currentGroup; | 49 : currentGroup = _currentGroup, |
| 50 _setup = _testSetup, |
| 51 _teardown = _testTeardown; |
| 45 | 52 |
| 46 bool get isComplete() => result != null; | 53 bool get isComplete() => result != null; |
| 47 | 54 |
| 55 void run() { |
| 56 if (_setup != null) { |
| 57 _setup(); |
| 58 } |
| 59 try { |
| 60 test(); |
| 61 } finally { |
| 62 if (_teardown != null) { |
| 63 _teardown(); |
| 64 } |
| 65 } |
| 66 } |
| 67 |
| 48 void pass() { | 68 void pass() { |
| 49 result = _PASS; | 69 result = _PASS; |
| 50 } | 70 } |
| 51 | 71 |
| 52 void fail(String message, String stackTrace) { | 72 void fail(String message, String stackTrace) { |
| 53 result = _FAIL; | 73 result = _FAIL; |
| 54 this.message = message; | 74 this.message = message; |
| 55 this.stackTrace = stackTrace; | 75 this.stackTrace = stackTrace; |
| 56 } | 76 } |
| 57 | 77 |
| 58 void error(String message, String stackTrace) { | 78 void error(String message, String stackTrace) { |
| 59 result = _ERROR; | 79 result = _ERROR; |
| 60 this.message = message; | 80 this.message = message; |
| 61 this.stackTrace = stackTrace; | 81 this.stackTrace = stackTrace; |
| 62 } | 82 } |
| 63 } | 83 } |
| OLD | NEW |