我一直在尝试使用SimpleTest开始对我的代码进行单元测试,我有一个可以独立工作的工作测试,但我想使用一个包含一系列测试的目录,而TestSuite将运行所有在那些测试中,我的工作测试是:
<?php
require_once(dirname(__FILE__) . '/../simpletest/autorun.php');
define("ROOT",'/var/web/trunk/');
require_once('/usr/share/log4php/src/main/php/Logger.php');
class TestBayCrazy extends UnitTestCase {
function testDatabase () {
require_once(ROOT.'includes/libs.inc.php');
$database = new Database();
$this->assertTrue($database->connected == TRUE);
$database = new Database('a','b','c','d','e');
$this->assertTrue($database->connected == FALSE);
$database = null;
}
}
我的TestSuite是:
<?php
require_once(dirname(__FILE__) . '/simpletest/autorun.php');
define("ROOT",'/var/web/trunk/');
require_once('/usr/share/log4php/src/main/php/Logger.php');
class AllTests extends TestSuite {
function AllTests() {
$this->TestSuite('All Tests');
$this->addFile('tests/testDatabase.php');
$this->addFile('tests/testSession.php');
$this->addFile('tests/testValidate.php');
}
}
但是在运行时会返回以下内容:
2011/10/05 12:37:47 [error] 3242#0: *309 FastCGI sent in stderr: "PHP Fatal error:
Call to a member function getDumper() on a non-object in
/var/web/trunk/private/simpletest/test_case.php on line 316 PHP Stack trace: PHP
1. simpletest_autorun() /var/web/trunk/private/simpletest/autorun.php:0 PHP
2. run_local_tests() /var/web/trunk/private/simpletest/autorun.php:28 PHP
3. TestSuite-run() /var/web/trunk/private/simpletest/autorun.php:52 PHP
4. TestSuite->run() /var/web/trunk/private/simpletest/test_case.php:563 PHP
5. TestSuite->run() /var/web/trunk/private/simpletest/test_case.php:563 PHP
6. TestSession->testSession() /var/web/trunk/private/simpletest/test_case.php:559 PHP
7. UnitTestCase->assertIsA() /var/web/trunk/private/tests/testSession.php:10 PHP
8. SimpleTestCase->assert() /var/web/trunk/private/simpletest/unit_tester.php:110"
while reading response header from upstream, client: 0.0.0.0,
server: example.com, request: "GET /private/unittest.php HTTP/1.1",
upstream: "fastcgi://127.0.0.1:9001", host: "0.0.0.0
那么,我到底做错了什么?我只找到了关于如何进行testSuite的示例,而不是当它是套件成员时测试需要如何不同,而不是独立(可能是因为我对单元测试的语言不熟悉)。
答案 0 :(得分:0)
我们实际上使用GroupTest而不是套件
$dbgroup = new GroupTest("running database tests");
$dbgroup->addTestFile('tests/testDatabase.php');
$dbgroup->run(new HtmlReporter());
它做得很好......