gpt4 book ai didi

PHPUnit 和 Selenium : setUpBeforeClass() not called

转载 作者:可可西里 更新时间:2023-11-01 01:09:01 26 4
gpt4 key购买 nike

我想使用 setUpBeforeClass() 来设置数据库连接,并进行一些日志记录,但在我的测试执行之前它没有被调用(或者根本没有被调用)。我有以下内容:

class TestSetup extends PHPUnit_Extensions_SeleniumTestCase {
public static function setUpBeforeClass() {
//do some setup stuff here for all my tests
}
protected function setUp() {
$this->setBrowserUrl('http://' . $this->deviceIp);
}
protected function testOne() {
//do a test here
}
protected function testTwo() {
//do a test here
}
}

我深入研究了 PHPUnit/Frameworks/TestSuite.php,并确认在第 660 行 $this->testCase 是 bool(false)。但我不知道它是否应该是真的,或者应该在哪里发生(除了在 __construct() 中)。

我在这里有点过头了,所以非常感谢任何帮助。

如果我可以提供任何其他有用的信息,请告诉我。

乔希

最佳答案

我在文档中找不到任何内容,但代码似乎与您一致。

PHPUnit/Extensions/SeleniumTestCase.php run 方法(第 289+ 行)中,没有调用 setUpBeforeClass(或任何其他可能调用的方法)的迹象。

如果您认为这是一个问题,我建议您在 phpunits issue tracker 上开票.

对于解决方法,您可以在 setUp 中使用静态属性,如下所示:

protected function setUp() {
static $db = null;
if($db === null) {
$db = whatevery_you_do_there();
}
$this->db = $db;
}

这应该可以工作,有点像您在 setUpBeforeClass()

中运行它一样

关于PHPUnit 和 Selenium : setUpBeforeClass() not called,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5316759/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com