After I checked out the Unit Testing class in CI and some other implemetations in CI of SimpleTest—such as Jamie Rumbelow’s (http://jamierumbelow.net/2009/08/11/setting-up-the-perfect-codeigniter-tdd-environment/)—I was kinda unhappy with CI’s presentation and SimpleTest’s ‘bloatedness’ so I decided to take CI’s class and improve it a little by addding some features and enhance its UI. You can see a screenshot of how it looks like below, in the attachments.
Deprecated. Latest version is here.
Main Features / Pros
* No external libraries, uses CI’s Unit Test class and Benchmark class for timings
* Allows you to run tests by category or one specific test. Possible categories are: Models, Views, Controllers, Helpers and Libraries.
* All tests you write are automatically categorized depending on the suffix you give them (e.g. _model, _helper, etc.)
* Gives you a summary of tests that were successful in a large bar on top, including total run time
* No complicated directory structure, all tests are in one controller/file
* Simple and easy implementation
Missing Features / Cons
* All tests being in one file might get a bit overwhelming if you make a lot of tests and if you are working with more than one developer/unit tester & working on one single file is not optimal even with revision control
* Not overloading CI’s Unit Test class, it’s edited directly (with reason: it’s just two lines!)
* Not yet tested thoroughly, but that’s why it’s here!
* More? Give feedback here!
Implementation
1. Grab the CSS from the attachments below (unit_test.zip) and put it where it makes sense to you (I use /assets/css/unit_test.css). Make sure to set the correct path in step 4.
2. Edit /system/libraries/Unit_test.php and locate the $result array near line 80 and add the two commented lines:
'test_datatype' => gettype($test),
'test_value' => $test, // Add this…
'res_datatype' => $extype,
'res_value' => $expected, // and this
'result' => ($result === TRUE) ? 'passed' : 'failed',3. Edit /system/language/english/unit_test_lang.php and add these two array values:
$lang['ut_test_value'] = 'Test Value';
$lang['ut_res_value'] = 'Expected Value';4. Add the view test_unit.php (see attached zip) to your view folder (or any subfolder, just make sure to correctly specify the path in the controller in the next step)
5. Last but not least, the controller test.php that you will place in your controller folder is included in the attached zip. The next post has the complete code pasted for convenience & analysis.
—Post truncated, see next post (character limit exceeded)—