Skip to content

Instantly share code, notes, and snippets.

@azazqadir azazqadir/readme.md
Last active Oct 29, 2018

Embed
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

<?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
You can’t perform that action at this time.