我已经开始对我的 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 根与服务器根表示法——任何想到的东西,但没有什么能让测试套件正常运行。有任何想法吗?