2011-10-28 213 views
0

我有一个简单的测试套件,我一直在为PHP中的一些最近的A​​PI封装代码编写代码。但每次运行测试时,它都会运行所有测试两次。Simpletest正在运行我所有的测试两次。为什么?

我的调用代码:

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 
} 

有没有什么更包括对autorun.php或其他电话要么authentication_test.php内SimpleTest的。

想法?

回答

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()的隐含方法,当你调用运行再次执行测试()方法。

+0

我不是一个SimpleTest的大师,但我一直在阅读文件和它说,你尝试使用代码,已经是嵌入在最简单的库中,这样你的测试就会自动识别你的记者使用,以防你使用命令行或浏览器。我建议你的代码实际上在适当的Reporter下运行在浏览器和命令行中。 –

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'); 
    } 
} 
?> 
+0

我会标记这是我的后续问题的解决方案,如果我可以标记多个标签。 –

相关问题