문제

I have a simpletest suite I've been working on writing for some of my recent API wrapper code in PHP. But every time I run the test, it runs all of the tests twice.

My calling code:

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 looks like:

class Test_CallLoop_Authentication extends UnitTestCase {  

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

There aren't any more includes to autorun.php or other calls to simpletest within authentication_test.php either.

Ideas?

도움이 되었습니까?

해결책

You should change your calling code like this:

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 file executes automatically your tests calling run() methods implicitly, when you call run() method you execute tests again.

다른 팁

From simpletests documentation, you should use the static method 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');
    }
}
?>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top