Show
Ignore:
Timestamp:
03/10/2008 05:17:44 PM (9 months ago)
Author:
Geert
Message:

Added stats to test report (e.g. "Passed: 4 / 5").

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/modules/unit_test/libraries/Unit_Test.php

    r2275 r2278  
    1212class Unit_Test_Core { 
    1313 
     14        // The path(s) to recursively scan for tests 
    1415        protected $paths = array(); 
     16 
     17        // The results of all tests from every test class 
    1518        protected $results = array(); 
     19 
     20        // Statistics for every test class 
     21        protected $stats = array(); 
    1622 
    1723        /** 
     
    6167                                        throw new Kohana_Exception('unit_test.test_class_not_found', $class, $path); 
    6268 
    63                                 // Instantiate test class results 
    64                                 $this->results[$class] = array(); 
    65  
    6669                                // Reverse-engineer Test class 
    6770                                $reflector = new ReflectionClass($class); 
     
    7073                                if ( ! $reflector->isSubclassOf(new ReflectionClass('Unit_Test_Case'))) 
    7174                                        throw new Kohana_Exception('unit_test.test_class_extends', $class); 
     75 
     76                                // Initialize test class results and stats 
     77                                $this->results[$class] = array(); 
     78                                $this->stats[$class] = array('passed' => 0, 'failed' => 0); 
    7279 
    7380                                // Loop through all the class methods 
     
    95102                                        { 
    96103                                                $object->$method_name(); 
     104 
     105                                                // Test passed 
    97106                                                $this->results[$class][$method_name] = TRUE; 
     107                                                $this->stats[$class]['passed']++; 
    98108                                        } 
    99109                                        catch (Kohana_Unit_Test_Exception $e) 
    100110                                        { 
     111                                                // Test failed 
    101112                                                $this->results[$class][$method_name] = $e; 
     113                                                $this->stats[$class]['failed']++; 
    102114                                        } 
    103115 
     
    122134        public function report() 
    123135        { 
    124                 return empty($this->results) ? '' : View::factory('kohana_unit_test')->set('results', $this->results)->render(); 
     136                if (empty($this->results)) 
     137                        return ''; 
     138 
     139                return View::factory('kohana_unit_test') 
     140                        ->set('results', $this->results) 
     141                        ->set('stats', $this->stats) 
     142                        ->render(); 
    125143        } 
    126144