diff options
author | Derek Allard <derek.allard@ellislab.com> | 2010-01-18 16:48:25 +0100 |
---|---|---|
committer | Derek Allard <derek.allard@ellislab.com> | 2010-01-18 16:48:25 +0100 |
commit | 0ce73efdef39b5760766fcdde08485e94b754953 (patch) | |
tree | f5bdb07547f7cfe3578ff86e80d3cfa23e2cf706 | |
parent | 2a064ef8014413c7c6d4c9c7456665c219529a49 (diff) |
The Unit Test Class now has an optional "notes" field available to it, and allows for discrete display of test result items using $this->unit->set_test_items().
-rw-r--r-- | system/libraries/Unit_test.php | 60 | ||||
-rw-r--r-- | user_guide/changelog.html | 3 | ||||
-rw-r--r-- | user_guide/libraries/unit_testing.html | 28 |
3 files changed, 74 insertions, 17 deletions
diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php index a6427b2c3..c47143637 100644 --- a/system/libraries/Unit_test.php +++ b/system/libraries/Unit_test.php @@ -28,19 +28,50 @@ */ class CI_Unit_test { - var $active = TRUE; - var $results = array(); - var $strict = FALSE; - var $_template = NULL; - var $_template_rows = NULL; + var $active = TRUE; + var $results = array(); + var $strict = FALSE; + var $_template = NULL; + var $_template_rows = NULL; + var $_test_items_visible = array(); function CI_Unit_test() { + // These are the default items visible when a test is run. + $this->_test_items_visible = array ( + 'test_name', + 'test_datatype', + 'res_datatype', + 'result', + 'file', + 'line', + 'notes' + ); + log_message('debug', "Unit Testing Class Initialized"); - } + } // -------------------------------------------------------------------- - + + /** + * Run the tests + * + * Runs the supplied tests + * + * @access public + * @param array + * @return void + */ + function set_test_items($items = array()) + { + if ( ! empty($items) AND is_array($items)) + { + $this->_test_items_visible = $items; + } + } + + // -------------------------------------------------------------------- + /** * Run the tests * @@ -52,7 +83,7 @@ class CI_Unit_test { * @param string * @return string */ - function run($test, $expected = TRUE, $test_name = 'undefined') + function run($test, $expected = TRUE, $test_name = 'undefined', $notes = '') { if ($this->active == FALSE) { @@ -83,11 +114,12 @@ class CI_Unit_test { 'res_datatype' => $extype, 'result' => ($result === TRUE) ? 'passed' : 'failed', 'file' => $back['file'], - 'line' => $back['line'] + 'line' => $back['line'], + 'notes' => $notes ); - $this->results[] = $report; - + $this->results[] = $report; + return($this->report($this->result($report))); } @@ -120,7 +152,6 @@ class CI_Unit_test { foreach ($res as $key => $val) { - if ($key == $CI->lang->line('ut_result')) { if ($val == $CI->lang->line('ut_passed')) @@ -203,6 +234,11 @@ class CI_Unit_test { $temp = array(); foreach ($result as $key => $val) { + if ( ! in_array($key, $this->_test_items_visible)) + { + continue; + } + if (is_array($val)) { foreach ($val as $k => $v) diff --git a/user_guide/changelog.html b/user_guide/changelog.html index 6dbdc1bed..b8601ab3a 100644 --- a/user_guide/changelog.html +++ b/user_guide/changelog.html @@ -69,6 +69,7 @@ SVN Revision: </p> <li>Added a <kbd>parse_string()</kbd> method to the <a href="libraries/parser.html">Parser Class</a>.</li> <li>Added HTTP headers and Config information to the <a href="general/profiling.html">Profiler</a> output.</li> <li>Added Chrome and Flock to the list of detectable browsers by <kbd>browser()</kbd> in the <a href="libraries/user_agent.html">User Agent Class</a>.</li> + <li>The <a href="libraries/unit_testing.html">Unit Test Class</a> now has an optional "notes" field available to it, and allows for discrete display of test result items using <kbd>$this->unit->set_test_items()</kbd>.</li> </ul> </li> <li>Database @@ -114,7 +115,7 @@ SVN Revision: </p> <li>Fixed a bug in reduce_double_slashes() in the String Helper to properly remove duplicate leading slashes (#7585)</li> <li>Fixed a bug in values_parsing() of the XML-RPC library which prevented NULL variables typed as 'string' from being handled properly.</li> <li>Fixed a bug were form_open_multipart() didn't accept string attribute arguments (#10930).</li> - <li>Fixed a bug (#10470) where <kdb>get_mime_by_extension()</kbd> case sensitive.</li> + <li>Fixed a bug (#10470) where <kdb>get_mime_by_extension()</kbd> was case sensitive.</li> </ul> <h2>Version 1.7.2</h2> diff --git a/user_guide/libraries/unit_testing.html b/user_guide/libraries/unit_testing.html index b9916045e..bf86738f4 100644 --- a/user_guide/libraries/unit_testing.html +++ b/user_guide/libraries/unit_testing.html @@ -79,10 +79,10 @@ to determine if it is producing the correct data type and result. <p>Running a test involves supplying a test and an expected result to the following function:</p> -<h2>$this->unit->run( <var>test</var>, <var>expected result</var>, '<var>test name</var>' );</h2> +<h2>$this->unit->run( <var>test</var>, <var>expected result</var>, '<var>test name</var>', '<var>notes</var>');</h2> -<p>Where <var>test</var> is the result of the code you wish to test, -<var>expected result</var> is the data type you expect, and <var>test name</var> is an optional name you can give your test. Example:</p> +<p>Where <var>test</var> is the result of the code you wish to test, <var>expected result</var> is the data type you expect, +<var>test name</var> is an optional name you can give your test, and <var>notes</var> are optional notes. Example:</p> <code>$test = 1 + 1;<br /> <br /> @@ -160,9 +160,29 @@ unit testing using:</p> <code>$this->unit->active(FALSE)</code> +<h2>Unit Test Display</h2> +<p>When your unit test results display, the following items show by default:</p> -<h2>Creating a Template</h2> +<ul> + <li>Test Name (test_name)</li> + <li>Test Datatype (test_datatype)</li> + <li>Expected Datatype (res_datatype)</li> + <li>Result (result)</li> + <li>File Name (file)</li> + <li>Line Number (line)</li> + <li>Any notes you entered for the test (notes)</li> +</ul> + +You can customize which of these items get displayed by using <kbd>$this->unit->set_items()</kbd>. For example, if you only wanted the test name and the result displayed:</p> + +<h3>Customizing displayed tests</h3> + +<code> + $this->unit->set_test_items(array('test_name', 'result')); +</code> + +<h3>Creating a Template</h3> <p>If you would like your test results formatted differently then the default you can set your own template. Here is an example of a simple template. Note the required pseudo-variables:</p> |