PHP SimpleTest - 使用多个测试用例
我一直在尝试使用 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
那么,我到底做错了什么?我只找到了有关如何进行测试套件的示例,而不是测试作为套件成员而不是独立测试时需要有所不同的示例(可能是因为我对单元测试语言不熟悉)。
I have been trying to use SimpleTest to begin unit testing my code, I have a working test that works on its own, but I want to use a single directory that will contain a range of tests, and a TestSuite will run all of those tests, my working test is:
<?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;
}
}
My TestSuite is:
<?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');
}
}
But this returns the following when run:
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
So, what on earth am I doing wrong? I've only found examples on how to do a testSuite, not how a test needs to be different when it's a member of a suite, rather than stand alone (may be down to my lack of familiarity with the language of unit testing).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我们实际上使用 GroupTest 而不是 Suite
它的工作做得足够好......
We actually use GroupTest instead of a Suite
It does the job well enough...