my-ciunit /

Filename Size Date modified Message
15 B
141 B
3.1 KB
5.0 KB

CIUnit Foostack

Originally created by: Clemens "rafsoaken" Gruenberger

Modified and Updated by:

  • Mario "Kuroir" Ricalde
  • Grzegorz "Grisha" Godlewski
  • Tatsuya Fukata
  • Kenji "kenjis" Suzuki


  • "default" branch is for CodeIgniter 2.1.0.
  • To CodeIgniter 2.0.3 users, please use "CI 2.0.3" branch. You can get the latest code from
  • Known Issues: See
  • CIUnit was updated to work completely with CodeIgniter 2.0.3.
  • CIUnit is completely separated from the CodeIgniter Core Files.
  • CIUnit has it's own modified core files and will load them only when needed (by using the console for instance).
  • CIUnit won't use the system index.php anymore, instead it'll use application/third_party/CIUnit/bootstrap_phpunit.php
  • This is to prevent CIUnit/Foostack to cause any extra load on production.

Folder structure:

  • application/third_party/CIUnit/bootstrap_phpunit.php (Application and System Folder)
  • tests/phpunit.xml (Optional: only edit if you want to move bootstrap_phpunit.php)


Install by shell script:

$ cd ciunit
$ tools/ CI2_Project_Path [DB_Name [DB_User [DB_Passwd [DB_host]]]]

Install manually:

$ cp -R ciunit/application CI2_Project_Path/
$ cp -R ciunit/tests CI2_Project_Path/

create application/config/testing/database.php for database testing. Database name must end with "_test".

If you use MY_Loader, MY_Output, MY_Session, please change the parent classes below:

  • application/third_party/CIUnit/core/CIU_*.php
  • application/third_party/CIUnit/libraries/CIU_*.php

Run Tests:

All Tests:

$ cd [CI2 Project Path]/tests
$ phpunit

Some Tests:

$ cd [CI2 Project Path]/tests
$ phpunit models

Single Test:

$ cd [CI2 Project Path]/tests
$ phpunit models/PhoneCarrierModelTest.php

(Optional) Execute Tests of CodeIgniter Unit Testing Class:


  • You must execute all tests in index() function of testing controllers.


function index()

    echo $this->unit->report();

See tests/controllers/CI_Unit_Test_class_Test.php. In test_CI_Unit_Test_Class() function, set the folder where testing controllers are in.

$test_path = APPPATH . 'controllers';
$test_folder = 'tests';

It runs all *.php files in "application/controllers/tests" folder.

PHPUnit shows all test file names and failed test names. If more than one test fails, PHPUnit reports 1 failure, even if 100 fails occurres.


If you are not familiar with PHPUnit/CIUnit, tutorial below may help you.

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.