Here’s simple method for unit testing in CI 2.x/3.x.
The test class in application/controllers
< ?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; } } |
automatic loading of the extended controller using __autoload
Open application/config/config.php and add these lines:
function __autoload($class){ if (file_exists(APPPATH."controllers/".strtolower($class).".php")){ require_once(APPPATH.'controllers/'.strtolower($class).".php"); } } |
Define the Route
Do this in application/config/routes.php:
$route['tests'] = "Frontend_Tests_Controller/index"; |
Open /tests in the browser to see the testing results.
Der Beitrag Automated unit testing for code igniter 2.x/3.x erschien zuerst auf notboring dev blog.