diff options
author | Andrew <browner12@gmail.com> | 2014-02-11 09:55:48 +0100 |
---|---|---|
committer | Andrew <browner12@gmail.com> | 2014-02-11 09:55:48 +0100 |
commit | b6d8b962e44202a74c9b9321a4a53f61a753fccf (patch) | |
tree | 2d3c533a55964a0d124f7cd6bb1d3d98c7b84056 /user_guide_src/source/libraries/unit_testing.rst | |
parent | 41713aaa665189dd0a191c333c73c4a7b9f37c78 (diff) | |
parent | 29e12641a1bb952f493462db6757ae12c7da1f2c (diff) |
Merge branch 'develop' into patch-1
Conflicts:
system/libraries/Calendar.php
Diffstat (limited to 'user_guide_src/source/libraries/unit_testing.rst')
-rw-r--r-- | user_guide_src/source/libraries/unit_testing.rst | 100 |
1 files changed, 88 insertions, 12 deletions
diff --git a/user_guide_src/source/libraries/unit_testing.rst b/user_guide_src/source/libraries/unit_testing.rst index 6bd91bf88..0bc860f61 100644 --- a/user_guide_src/source/libraries/unit_testing.rst +++ b/user_guide_src/source/libraries/unit_testing.rst @@ -11,6 +11,13 @@ evaluation function and two result functions. It's not intended to be a full-blown test suite but rather a simple mechanism to evaluate your code to determine if it is producing the correct data type and result. +.. contents:: + :local: + +.. raw:: html + + <div class="custom-index container"></div> + Initializing the Class ====================== @@ -19,16 +26,15 @@ initialized in your controller using the $this->load->library function:: $this->load->library('unit_test'); -Once loaded, the Unit Test object will be available using: $this->unit +Once loaded, the Unit Test object will be available using ``$this->unit`` Running Tests ============= -Running a test involves supplying a test and an expected result to the -following function: +Running a test involves supplying a test and an expected result in the +following way: -$this->unit->run( test, expected result, 'test name', 'notes'); -=============================================================== + $this->unit->run('test', 'expected result', 'test name', 'notes'); Where test is the result of the code you wish to test, expected result is the data type you expect, test name is an optional name you can give @@ -114,7 +120,7 @@ Enabling/Disabling Unit Testing If you would like to leave some testing in place in your scripts, but not have it run unless you need it, you can disable unit testing using:: - $this->unit->active(FALSE) + $this->unit->active(FALSE); Unit Test Display ================= @@ -150,15 +156,85 @@ template. Note the required pseudo-variables:: $str = ' <table border="0" cellpadding="4" cellspacing="1"> - {rows} - <tr> - <td>{item}</td> - <td>{result}</td> - </tr> - {/rows} + {rows} + <tr> + <td>{item}</td> + <td>{result}</td> + </tr> + {/rows} </table>'; $this->unit->set_template($str); .. note:: Your template must be declared **before** running the unit test process. + +*************** +Class Reference +*************** + +.. class:: CI_Unit_test + + .. method:: set_test_items($items) + + :param array $items: List of visible test items + :returns: void + + Sets a list of items that should be visible in tests. + Valid options are: + + - test_name + - test_datatype + - res_datatype + - result + - file + - line + - notes + + .. method:: run($test[, $expected = TRUE[, $test_name = 'undefined'[, $notes = '']]]) + + :param mixed $test: Test data + :param mixed $expected: Expected result + :param string $test_name: Test name + :param string $notes: Any notes to be attached to the test + :returns: Test report + :rtype: string + + Runs unit tests. + + .. method:: report([$result = array()]) + + :param array $result: Array containing tests results + :returns: Test report + :rtype: string + + Generates a report about already complete tests. + + .. method:: use_strict([$state = TRUE]) + + :param bool $state: Strict state flag + :rtype: void + + Enables/disables strict type comparison in tests. + + .. method:: active([$state = TRUE]) + + :param bool $state: Whether to enable testing + :rtype: void + + Enables/disables unit testing. + + .. method:: result([$results = array()]) + + :param array $results: Tests results list + :returns: Array of raw result data + :rtype: array + + Returns raw tests results data. + + .. method:: set_template($template) + + :param string $template: Test result template + :rtype: void + + Sets the template for displaying tests results.
\ No newline at end of file |