Permalink
Browse files

Adding time and memory output to the test suite results.

  • Loading branch information...
1 parent edf5f2d commit ea7df4f7ce658625073f583cf6c6c04fa9f59faa @markstory markstory committed Sep 13, 2009
Showing with 46 additions and 0 deletions.
  1. +45 −0 cake/tests/lib/cake_reporter.php
  2. +1 −0 cake/tests/lib/test_manager.php
@@ -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
@@ -53,6 +57,41 @@ function CakeHtmlReporter($character_set = 'ISO-8859-1') {
}
/**
+ * 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.
*
@@ -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>';
}
/**
@@ -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";

0 comments on commit ea7df4f

Please sign in to comment.