Skip to content

Instantly share code, notes, and snippets.

@azazqadir azazqadir/

Last active Oct 29, 2018
What would you like to do?
Unit Testing in CodeIgniter Projects

An example of test case in n CodeIgniter.

class Testcase extends  CI_Controller


public function get_testcase(){

    $this ->load ->view('view_testcase');



To run Codeigniter PHPunit testing, add the above code in testcase.php file. Now, create checkunit_text.php to test the get_testcase() by adding this code:

class Checkunit_test extends  UnitTest


public function unit_test_check()


       $output=$this -> request('GET',['Testcase','get_testcase']);

    $expected = 'Unit Test';

    $this -> assertContains($expected,$output);



Use this code to create view


define('BASEPATH') OR exit('access not allowed');


Now run the test

type the command $cd application/testcase/(application folder name) command to run the test → $ phpunit –phpunit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.