Anyone using CodeIgniter use automated unit testing?
Seems the way CodeIgniter's guy do unit test need to have a controller which run in browser,
e.g.
- http://codeigniter.com/user_guide/libraries/unit_testing.html
- or this: http://jensroland.com/projects/toast/
However, I only want to test from command line, I want automated test and 开发者_运维技巧build.
Any recommendation?
Thanks.
You can use this integration with phpunit - http://www.foostack.com/foostack/
It would then run from the command line.
Here's what I do:
- Download Test.php
- Create a 't' directory at the root of my CI app
- Put Test.php in the t directory
- Create a bootstrap.php file (see below) to initialize testing
require_once
the bootstrap.php file in my tests.- Run
prove
on tests in the t directory
bootstrap.php
:
<?php
// Initialize CodeIgniter, suppressing output.
ob_start();
require_once __DIR__ . '/../index.php';
ob_end_clean();
require_once __DIR__ . '/Test.php';
An example of a test:
t/000-sanity.t
:
#!/usr/bin/env php
<?php
require_once 'bootstrap.php';
plan(1);
is(true, true, 'Test.php works');
All CodeIgniter stuff is available. For example, you can do $ci =& get_instance();
This setup works great in CI 1.7.x and 2.x. Test.php is really easy to use, as well.
精彩评论