我仅仅是做测试,随便写的
首先在libraries里写你自己的类
复制内容到剪贴板PHP 代码:
<?php if (!
defined('BASEPATH')) exit('No direct script access allowed');
class Image
{var $url =
"";
function My_image
($url) { echo "<hr/>";
echo "<font color = 'red'>The url is:$url".
"</font>";
echo "<hr/>";
} function Re_image
($name) { echo "The image name is $name";
} function A_image
() { return "AA";
}}?> 然后在controller里任一function里进行测试
复制内容到剪贴板PHP 代码:
function image_unit
() { echo "test...";
$this->
load->
library('unit_test');
$this->
load->
library('Image');
$test =
$this->
image->
a_image();
$expected_result =
'AA';
$test_name =
'Image Unit';
echo $this->
unit->
run($test,
$expected_result,
$test_name);
} 有点注意:调用时的类名,函数名必须小写,搞了我半天,汗。
你还可以进行类型测试,
这是对结果进行测试。
| Test Name | Image Unit |
| Test Datatype | String |
| Expected Datatype | String |
| Result | Passed |
| File Name | D:\webroot\x.cn\CodeIgniter_1.6.3\system\application\controllers\welcome.php |
| Line Number | 549 |
若有什么错误,请指正。谢谢