简体   繁体   English

PHP SimpleTest-使用多个测试用例

[英]PHP SimpleTest - Using multiple test cases

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: 我一直在尝试使用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;
  }

}

My TestSuite is: 我的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');
  }
}

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). 我仅找到有关如何执行testSuite的示例,而不是有关作为套件成员的测试有何不同的信息,而不是独立的(可能是由于我对单元测试语言缺乏了解)。

We actually use GroupTest instead of a Suite 我们实际上使用GroupTest而不是Suite

$dbgroup = new GroupTest("running database tests");
$dbgroup->addTestFile('tests/testDatabase.php');
$dbgroup->run(new HtmlReporter());

It does the job well enough... 它做得很好...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM