2011-10-28 132 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

我會標記這是我的後續問題的解決方案,如果我可以標記多個標籤。 –

相關問題