Pergunta

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?

Foi útil?

Solução

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.

Outras dicas

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');
    }
}
?>
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top