Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(571)

Unified Diff: lib/unittest/unittest.dart

Issue 10579008: Added test setup/teardown. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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) {

Powered by Google App Engine
This is Rietveld 408576698