【发布时间】:2015-10-02 13:53:34
【问题描述】:
我正在做 WordPress 功能测试,所以我阅读了 HTML 并使用 Mastermind/HTML5 来转换测试。但是,现在的测试变得越来越慢,因为每次测试加载 HTML 文档大约需要 1 秒。我想在测试之间共享夹具,所以我不必为每个测试进行解析。但是我有一个限制,从中获取 html 的方法是在父类中,它是非静态方法
https://core.trac.wordpress.org/browser/trunk/tests/phpunit/includes/testcase.php?rev=32953#L328
我有什么选择在测试之间共享夹具。
这是我的示例代码
class Testcase extends WP_UnitTestCase {
public function setUp() {
parent::setUp();
}
public function get_dom( $path ) {
$html = $this->go_to( $path ); // I cannot change this method
// do some html parsing and return DOM
}
}
这是我的示例测试
class Testcase1 extends Testcase {
public setUp(){
$this->dom = $this->get_dom('/')
}
public test_1() {
}
public test_2() {
}
}
我正在考虑将方法 get_dom 设为静态,因此它只会被调用一次,但据我所知静态方法不能调用非静态方法。我对么?如果是的话,我可以在测试之间共享夹具吗?
【问题讨论】:
标签: php wordpress performance unit-testing