Here’s a quick way to setup unit testing for CI 2.x/3.x:
Step 1: Add a class for testing into your application/controllers folder:
< ?php class Frontend_Tests_Controller extends Frontend_Controller{ function __construct(){ parent::__construct(); } public function index(){ $this->load->library('unit_test'); $this->unit->run( $this->test_reflection(5), 5, "Testing testing" ); echo $this->unit->report(); } protected function test_reflection($value){ return $value; } } |
In this file you can add all your tests and then call them from the index function.
Step 2: Add auto loading code for your new testing class to application/config/config.php:
function __autoload($class){ if (file_exists(APPPATH."controllers/".strtolower($class).".php")){ require_once(APPPATH.'controllers/'.strtolower($class).".php"); } } |
Step 3: Add the route to application/config/routes.php
$route['tests'] = "Frontend_Tests_Controller/index"; |
Now you can call