      }
      
      /**
-@@ -279,15 +285,49 @@
+@@ -279,15 +287,45 @@
       *
       * @param   unittest.TestCase test
       * @return  unittest.TestResult

+        throw new MethodNotImplementedException('Test method '.$test->name.'() does not exist');
+      }
       $this->notifyListeners('testRunStarted', array($this));
       
+      // Check for methods annotated with beforeClass
+      $skip= NULL;
+      foreach ($test->getClass()->getMethods() as $m) {
+        if (!$m->hasAnnotation('beforeClass')) continue;
+        
+        try {
+          $m->invoke(NULL, array());
+        } catch (TargetInvocationException $e) {
+          $skip= $e->getCause();
+        }
+        break;
+      }
+
       // Run the single test case
       $result= new TestResult();
-      $this->runInternal($test, $result);
+      if ($skip) {
+        $this->notifyListeners('testSkipped', array(
+          $result->setSkipped($test, $skip, 0.0)
+        ));
+      } else {
+        $this->runInternal($test, $result);
+      }
 
+      // Notify listeners
       $this->notifyListeners('testRunFinished', array($this, $result));
+
+      // Check for methods annotated with afterClass
+      foreach ($test->getClass()->getMethods() as $m) {
+        if (!$m->hasAnnotation('afterClass')) continue;

       $listeners = array();
 
     /**
@@ -53,6 +54,9 @@
       if (!$test->getClass()->getMethod($test->name)) {
         throw new MethodNotImplementedException('Test method '.$test->name.'() does not exist');
       }
+      $className= $test->getClassName();
+      if (!isset($this->order[$className])) $this->order[$className]= array();
+      $this->order[$className][$test->name]= sizeof($this->tests);
       $this->tests[]= $test;
       return $test;
     }
@@ -73,18 +77,21 @@
 
       $ignored= array();
       $numBefore= $this->numTests();
+      $className= $class->getName();
+      $this->order[$className]= array();
       foreach ($class->getMethods() as $m) {
         if (!$m->hasAnnotation('test')) continue;
         if ($m->hasAnnotation('ignore')) $ignored[]= $m;
 
-        // Add test method
-        $this->addTest(call_user_func_array(array($class, 'newInstance'), array_merge(
+        $this->order[$className][$m->getName()]= sizeof($this->tests);
+        $this->tests[]= call_user_func_array(array($class, 'newInstance'), array_merge(
           (array)$m->getName(TRUE),
           $arguments
