Index: lib/unittest/unittest.dart |
=================================================================== |
--- lib/unittest/unittest.dart (revision 8828) |
+++ lib/unittest/unittest.dart (working copy) |
@@ -175,6 +175,12 @@ |
*/ |
Function _testRunner; |
+/** Setup function called before each test in a group */ |
+Function _testSetup; |
+ |
+/** Teardown function called after each test in a group */ |
+Function _testTeardown; |
+ |
/** Current test being executed. */ |
int _currentTest = 0; |
@@ -504,11 +510,12 @@ |
* Creates a new named group of tests. Calls to group() or test() within the |
* body of the function passed to this will inherit this group's description. |
*/ |
-void group(String description, void body()) { |
+void group(String description, void body(), |
+ [Function setupTest, Function teardownTest]) { |
Bob Nystrom
2012/06/19 23:38:33
Instead of taking these functions as arguments, ho
gram
2012/06/20 17:44:14
Done.
|
ensureInitialized(); |
// Concatenate the new group. |
- final oldGroup = _currentGroup; |
+ final parentGroup = _currentGroup; |
if (_currentGroup != '') { |
// Add a space. |
_currentGroup = '$_currentGroup $description'; |
@@ -517,11 +524,20 @@ |
_currentGroup = description; |
} |
+ // Groups can be nested, so we need to preserve the current |
+ // settings for test setup/teardown |
Bob Nystrom
2012/06/19 23:38:33
.
gram
2012/06/20 17:44:14
Done.
|
+ Function parentSetup = _testSetup; |
+ Function parentTeardown = _testTeardown; |
+ |
try { |
+ _testSetup = setupTest; |
+ _testTeardown = teardownTest; |
body(); |
} finally { |
// Now that the group is over, restore the previous one. |
- _currentGroup = oldGroup; |
+ _currentGroup = parentGroup; |
+ _testSetup = parentSetup; |
+ _testTeardown = parentTeardown; |
} |
} |
@@ -648,7 +664,7 @@ |
guardAsync(() { |
_callbacksCalled = 0; |
_state = _RUNNING_TEST; |
- testCase.test(); |
+ testCase.run(); |
if (_state != _UNCAUGHT_ERROR) { |
if (testCase.callbacks == _callbacksCalled) { |