开发者

PHPUnit and Selenium: setUpBeforeClass() not called

I want to use setUpBeforeClass() to setup a db connection, and do some logging, but it is not being called before my tests execute (or at all, for that matter). I have the following:

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
    }
}

I did some digging into PHPUnit/Frameworks/TestSuite.php and have confirmed that on line 660 that $this->testCase is bool(false). But I couldn't figure out if it should be true or where that should happen (other than in __construct()).

I'm slightly over my head here, so any help would be greatly appreciated.

Let me know if I can provide any other helpful informatio开发者_如何学运维n.

Josh


I couldn't find anything in the docs but the code seems to agree with you.

In PHPUnit/Extensions/SeleniumTestCase.php run method (line 289+) there is no sign of calling setUpBeforeClass (or any other method that might do so).

If you consider that an issue I'd suggest opening a ticket on phpunits issue tracker.

For a workaround you could use a static property in setUp like this:

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

that should work, sort of, as if you'd run it in setUpBeforeClass()

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜