summaryrefslogtreecommitdiffstats
path: root/user_guide_src/source/libraries
diff options
context:
space:
mode:
Diffstat (limited to 'user_guide_src/source/libraries')
-rw-r--r--user_guide_src/source/libraries/unit_testing.rst97
1 files changed, 85 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..2d4a27a25 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,82 @@ 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: string
+
+ Runs unit tests.
+
+ .. method:: report([$result = array()])
+
+ :param array $result: Array containing tests results
+ :returns: string
+
+ Generates a report about already complete tests.
+
+ .. method:: use_strict([$state = TRUE])
+
+ :param bool $state: Strict state flag
+ :returns: void
+
+ Enables/disables strict type comparison in tests.
+
+ .. method:: active([$state = TRUE])
+
+ :param bool $state: Whether to enable testing
+ :returns: void
+
+ Enables/disables unit testing.
+
+ .. method:: result([$results = array()])
+
+ :param array $results: Tests results list
+ :returns: array
+
+ Returns raw tests results data.
+
+ .. method:: set_template($template)
+
+ :param string $template: Test result template
+ :returns: void
+
+ Sets the template for displaying tests results. \ No newline at end of file