Simpletest 将我的所有测试运行两次。为什么?
我有一个简单的测试套件,一直致力于为我最近用 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 的其他调用。
有想法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该像这样更改您的调用代码:
autorun.php 文件会自动执行隐式调用 run() 方法的测试,当您调用 run() 方法时,您会再次执行测试。
You should change your calling code like this:
autorun.php file executes automatically your tests calling run() methods implicitly, when you call run() method you execute tests again.
从 simpletests 文档来看,您应该使用静态方法
prefer(REPORTER)
From simpletests documentation, you should use the static method
prefer(REPORTER)