ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Improved CodeIgniter Unit Testing

September 15, 2009 11:46pm

Subscribe [15]
  • #16 / Oct 28, 2009 2:14am

    istvanp

    11 posts

    [DEPRECATED] Click here for latest version
    Improved CodeIgniter Unit Testing 1.0.1

    Change Log
    Version 1.0.1
    ——————-
    - Now overloading the CI Unit Test class
    - Removed support for testing controllers due to CI limitation
    - SQL errors are now displayed in the test report if a test case fails

    For new users
    - Download the zip attached to this post.
    - Extract the zip on top of your CI install directory if you did not change the path to your application or system folder (replace files as needed). Otherwise, extract to a temporary directory and move files as needed.

    That’s it! Now you can open the test.php controller and start adding your own tests. A sample function has been provided to show you how to create your own. After you have written some tests, you can test them by accessing siteurl.com/test/.

    Update procedure from 1.0 to 1.0.1
    - Download the zip attached to this post.
    - Extract the files in a temporary directory
    - Copy the file MY_Test_unit.php from application/libraries into your application/libraries folder
    - Open your original view unit_test.php and delete the line:

    <input type="button" value="Controllers" onclick="window.1ocation='<?=site_url("test/controllers")?>'" />

    Also check that the CSS location is correctly referenced.
    - Open your original test controller test.php and delete the following

    case 'controllers':
    else if (strripos($method, 'controller')  === $length - 10)
    {
        $this->tests['controllers'][] = $method;
    }

    - Overwrite your /system/language/english/unit_test_lang.php with the one you extracted

  • #17 / Dec 17, 2009 9:53am

    Nicolas Santos

    10 posts

    Hi all,

    thanx for the updates. it works really fine for me.  Go go testing time !

  • #18 / Jan 16, 2010 7:26am

    istvanp

    11 posts

    Improved CodeIgniter Unit Testing 1.0.2 (Latest version)

    Change Log
    Version 1.0.2
    ——————-
    Release date: January 16th, 2010

    - Added missing array_search_recusrive() function to controller (was accidentally removed in version 1.0.1, thanks for pointing this out khal3d)
    - Modified test mapping function and view to be able to easily change the name of the controller
    - Modified the view to use site_url()
    - Modified the view to show test groups in selection box

    For new users
    1. Download the zip attached to this post.
    2. Extract the zip on top of your CI install directory if you did not change the path to your application or system folder (replace files as needed). Otherwise, extract to a temporary directory and move files as needed.
    3. Optionally also follow the second step (2) in the update procedure given below

    That’s it! Now you can open the test.php controller and start adding your own tests. A sample function has been provided to show you how to create your own. After you have written some tests, you can test them by accessing siteurl.com/test/.

    Update procedure from 1.0.1 to 1.0.2
    1. Replace application/views/unit_test.php with new version included in the zip.
    2. Cut and paste the function array_search_recursive contained in application/controller/test.php into a new helper (see CI user guide on how to make helpers) and make sure to load it either in the constructor or add it to $autoload[‘helper’] array (in application/config/autoload.php). You could optionally add it to an existing CI helper such as array_helper.php but don’t forget to load it. (I personally added it to array_helper and I am auto loading it.)

  • #19 / Dec 09, 2010 5:35am

    helle

    15 posts

    trying your things out.
    but it simply does not work for me. i have an error on line 194. undefined index Result ...
    can you help me?

    thanks

    here my function listed in the test controller

    public function user_model(){
                $this->benchmark->mark('start');
                $test = true;
                $this->unit->run($test, TRUE, 'my first test with codeigniter');
                $this->benchmark->mark('end');
                $this->timings[] = $this->benchmark->elapsed_time('start', 'end');
            }
  • #20 / Dec 09, 2010 6:14am

    istvanp

    11 posts

    helle,

    It seems you might not be using the English language file I provided. If

    $lang['ut_result'] = 'Result';

    is not ‘Result’ that’s the error you would get. It is odd you do not get errors for the other strings though.
    The file in question is in system\language\english\unit_test_lang.php

  • #21 / Dec 09, 2010 6:17am

    helle

    15 posts

    ah okay. i see. had now language file in my german lang folder which provides your language stuff.
    copied the english one into the german folder => works fine!

  • #22 / Dec 09, 2010 6:21am

    istvanp

    11 posts

    Glad it worked. It’s good you reported this, I should be using local language strings instead of hard coding them directly. This should be fixed in the next version and compatibility with CI 2.x as well.

  • #23 / Mar 08, 2011 7:06am

    vikascoollives

    25 posts

    As per my view there is no need to test the controller functions for unit testing as it is integration of many functions of models , helpers etc.

    So perform unit testing on those function only . If the test passes the test for controller will pass automatically.

    We can perform integration testing for controller functions .may be!!!

  • #24 / Jun 14, 2012 2:44am

    istvanp

    11 posts

    This project has a new home at https://github.com/istvanp/CodeIgniter-UnitTest.
    However it is no longer maintained by me. Send your pull requests though.

  • #25 / Aug 08, 2013 10:07am

    linka

    1 posts

    hi istvanp, thanks for the link..
    i fast reading the documentation, and i find that this tools is really interesting.
    but can this tools implemented in Codeigniter?
    as you know CI controller / model / plugin etc, never use Calls to include, it will generate the right profiling result?
    regards

    i would like to reccomed to visit this link - something more relevant to your problem: http://myunittesting.com/

     

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases