Changeset 2278

Show
Ignore:
Timestamp:
03/10/08 17:17:44 (6 months ago)
Author:
Geert
Message:

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

Location:
trunk/modules/unit_test
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/modules/unit_test/controllers/unit_test.php

    r2267 r2278  
    1717    { 
    1818        // Run tests and show results! 
    19         $test = new Unit_Test(MODPATH.'unit_test/tests/'); 
    20         echo $test->report(); 
     19        echo new Unit_Test(MODPATH.'unit_test/tests'); 
    2120    } 
    2221 
  • trunk/modules/unit_test/i18n/en_US/unit_test.php

    r2274 r2278  
    88    'test_class_extends'   => '%s must extend Unit_Test_Case.', 
    99    'no_tests_found'       => 'No tests found', 
     10    'stats'                => 'Passed: %s / %s', 
    1011    'passed'               => 'Passed', 
    1112    'failed'               => 'Failed', 
  • 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 
  • trunk/modules/unit_test/views/kohana_unit_test.php

    r2274 r2278  
    3939    border-bottom: 1px solid #E5EFF8; 
    4040    padding: 3px; 
     41} 
     42#kohana-unit-test .k-stats 
     43{ 
     44    font-weight: normal; 
     45    color: #83919C; 
     46    text-align: right; 
    4147} 
    4248#kohana-unit-test .k-debug 
     
    8793    <table> 
    8894        <tr> 
    89             <th colspan="2"><?php echo $class ?></th> 
     95            <th><?php echo $class ?></th> 
     96            <th class="k-stats"> 
     97                <?php echo Kohana::lang('unit_test.stats', $stats[$class]['passed'], array_sum($stats[$class])) ?> 
     98            </th> 
    9099        </tr> 
    91100