Skip to content

Commit

Permalink
Adding time and memory output to the test suite results.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Sep 13, 2009
1 parent edf5f2d commit ea7df4f
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
45 changes: 45 additions & 0 deletions cake/tests/lib/cake_reporter.php
Expand Up @@ -37,6 +37,10 @@ class CakeHtmlReporter extends SimpleReporter {
var $_character_set;
var $_show_passes = false;

var $_timeStart = 0;
var $_timeEnd = 0;
var $_timeDuration = 0;

/**
* Does nothing yet. The first output will
* be sent on the first test start. For use
Expand All @@ -52,6 +56,41 @@ function CakeHtmlReporter($character_set = 'ISO-8859-1') {
$this->_character_set = $character_set;
}

/**
* Signals / Paints the beginning of a TestSuite executing.
* Starts the timer for the TestSuite execution time.
*
* @param
* @return void
**/
function paintGroupStart($test_name, $size) {
$this->_timeStart = $this->_getTime();
parent::paintGroupStart($test_name, $size);
}

/**
* Signals/Paints the end of a TestSuite. All test cases have run
* and timers are stopped.
*
* @return void
**/
function paintGroupEnd($test_name) {
$this->_timeEnd = $this->_getTime();
$this->_timeDuration = $this->_timeEnd - $this->_timeStart;
parent::paintGroupEnd($test_name);
}

/**
* Get the current time in microseconds. Similar to getMicrotime in basics.php
* but in a separate function to reduce dependancies.
*
* @return float Time in microseconds
**/
function _getTime() {
list($usec, $sec) = explode(' ', microtime());
return ((float)$sec + (float)$usec);
}

/**
* Paints the top of the web page setting the
* title to the name of the starting test.
Expand Down Expand Up @@ -102,6 +141,12 @@ function paintFooter($test_name) {
echo "<strong>" . $this->getFailCount() . "</strong> fails and ";
echo "<strong>" . $this->getExceptionCount() . "</strong> exceptions.";
echo "</div>\n";
echo '<div style="padding:0 0 5px;">';
echo '<p><strong>Time taken by tests (in seconds):</strong> ' . $this->_timeDuration . '</p>';
if (function_exists('memory_get_peak_usage')) {
echo '<p><strong>Peak memory use: (in bytes):</strong> ' . number_format(memory_get_peak_usage()) . '</p>';
}
echo '</div>';
}

/**
Expand Down
1 change: 1 addition & 0 deletions cake/tests/lib/test_manager.php
Expand Up @@ -619,6 +619,7 @@ function &getTestCaseList() {
return $buffer;
}
}

if (function_exists('caketestsgetreporter')) {
echo "You need a new test.php. \n";
echo "Try this one: " . dirname(CONSOLE_LIBS) . "templates" . DS . "skel" . DS . "webroot" . DS . "test.php";
Expand Down

0 comments on commit ea7df4f

Please sign in to comment.