我已经开始对我的PHP程序使用单元测试,并认为Simpletest是一个很好的潜水地点。我将Simpletest文件添加到我的测试服务器,并在我的自定义PDO类上运行以下测试:
<?php
require_once('../simpletest/autorun.php');
require_once('../includes/inc_sql.php');
class TestOfSQL extends UnitTestCase{
function testRead(){
...
}
function testWriteAndDelete(){
...
}
}
?>
这一切都很糟糕。我尝试构建一个涉及(到目前为止)测试文件的测试套件,如下所示:
<?php
require_once('../simpletest/autorun.php');
class AllTests extends TestSuite {
function __construct(){
parent::__construct();
$this->addFile('inc_sql_test.php');
}
}
这会崩溃并烧伤,我得到以下读数:
Warning: include_once(inc_sql_test.php) [function.include-once]: failed to open stream: No such file or directory in E:\xampp\htdocs\historicMuncie\simpletest\test_case.php on line 382
Warning: include_once() [function.include]: Failed opening 'inc_sql_test.php' for inclusion (include_path='.;E:\xampp\php\PEAR') in E:\xampp\htdocs\historicMuncie\simpletest\test_case.php on line 382
Warning: file_get_contents(inc_sql_test.php) [function.file-get-contents]: failed to open stream: No such file or directory in E:\xampp\htdocs\historicMuncie\simpletest\test_case.php on line 418
all_tests.php
Fail: AllTests -> inc_sql_test.php -> Bad TestSuite [inc_sql_test.php] with error [No runnable test cases in [inc_sql_test.php]]
0/0 test cases complete: 0 passes, 1 fails and 0 exceptions.
我已经使用了包含路径,Web根目录与服务器根表示法 - 我想到的任何事情,但没有任何东西允许该测试套件正常运行。有什么想法吗?
答案 0 :(得分:2)
当我在PHP脚本中看到相对路径时,我总是畏缩不前。当使用基于公共根的“半绝对”路径时,实现和维护要容易得多。尝试:
$this->addFile( $_SERVER['DOCUMENT_ROOT'] . '/inc_sql_test.php' );
答案 1 :(得分:0)
你也可以这样做:
$this->addFile(dirname(__FILE__) . '/inc_sql_test.php');
问候!