0

我有一个最简单的套件,我一直在为我最近用 PHP 编写的一些 API 包装器代码编写代码。但是每次我运行测试时,它都会运行所有测试两次。

我的调用代码:

require_once(dirname(__FILE__) . '/simpletest/autorun.php');  
require_once('CompanyNameAPI.php');


$test = new TestSuite('API test');
$test->addFile(dirname(__FILE__) . '/tests/authentication_test.php');
if (TextReporter::inCli()) {
    exit ($test->run(new TextReporter()) ? 0 : 1);
} else {
    $test->run(new HtmlReporter());
}

authentication_test.php 看起来像:

class Test_CallLoop_Authentication extends UnitTestCase {  

    function test_ClassCreate(){
        $class = new CallLoopAPI();
        $this->assertIsA($class, CallLoopAPI);
    }
        //More tests
}

在 authentication_test.php 中也不再包含 autorun.php 或其他对 simpletest 的调用。

想法?

4

2 回答 2

2

您应该像这样更改调用代码:

require_once(dirname(__FILE__) . '/simpletest/autorun.php');  
require_once('CompanyNameAPI.php');

$test = new TestSuite('API test');
$test->addFile(dirname(__FILE__) . '/tests/authentication_test.php');

autorun.php 文件会自动执行您的测试,隐式调用 run() 方法,当您调用 run() 方法时,您会再次执行测试。

于 2011-12-06T18:20:44.783 回答
0

从 simpletests 文档中,您应该使用静态方法prefer(REPORTER)

<?php
require_once('show_passes.php');
require_once('simpletest/simpletest.php');
SimpleTest::prefer(new ShowPasses());
require_once('simpletest/autorun.php');

class AllTests extends TestSuite {
    function __construct() {
        parent::__construct('All tests');
        $this->addFile(dirname(__FILE__).'/log_test.php');
        $this->addFile(dirname(__FILE__).'/clock_test.php');
    }
}
?>
于 2013-05-17T05:27:11.097 回答