Skip to content

Instantly share code, notes, and snippets.

@azazqadir
Last active October 29, 2018 14:29
Show Gist options
  • Save azazqadir/eb5805839eec4a12723eabb9380c3261 to your computer and use it in GitHub Desktop.
Save azazqadir/eb5805839eec4a12723eabb9380c3261 to your computer and use it in GitHub Desktop.
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

<?php

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