How do I solve this error: “Class PHPUnit_Extensio

2019-03-24 21:00发布

I am trying to run a SeleniumTestCase with phpunit but I cannot get it to run with the phpunit.bat script.

My goal is to use phpunit with Selenium RC in CruiseControl & phpUnderControl. This is what the test looks like:

require_once 'PHPUnit/Extensions/SeleniumTestCase.php';

class WebTest extends PHPUnit_Extensions_SeleniumTestCase
{
    protected function setUp()
    {
        $this->setBrowser('*firefox');
        $this->setBrowserUrl('http://www.example.com/');
    }

    public function testTitle()
    {
        $this->open('http://www.example.com/');
        $this->assertTitleEquals('Example Web Page');
    }
}

I also got PEAR in the include_path and PHPUnit installed with the Selenium extension. I installed these with the pear installer so I guess that's not the problem.

Any help would be very much appreciated.

Thanks, Remy

10条回答
Viruses.
2楼-- · 2019-03-24 21:48

Have a look at one of the comments in the require_once entry in the php manual..

http://ie.php.net/manual/en/function.require-once.php#62838

"require_once (and include_once for that matters) is slow

Furthermore, if you plan on using unit tests and mock objects (i.e. including mock classes before the real ones are included in the class you want to test), it will not work as require() loads a file and not a class."

查看更多
一纸荒年 Trace。
3楼-- · 2019-03-24 21:48

Well when I use inline command : if lauching test from PhPunit dir i have the error while whent launching it from test dir I havne't the error ...

but I still haven't any acces to selenium server ... shall I have to launch it before or not.

If Yes it's strange that we havne't to specify any handle to PhPUnit ...

查看更多
爱情/是我丢掉的垃圾
4楼-- · 2019-03-24 21:51

hopefully this is a more definitive answer then the ones given here (which did not solve me problem). If you are getting this error, check your PEAR folder and see if the "SeleniumTestCase.php" file is actually there:

/PEAR/PHPUnit/Extensions/SeleniumTestCase.php

If it is NOT, the easiest thing to do is to uninstall and reinstall PHPUnit using PEAR ...

pear uninstall phpunit/PHPUnit

pear uninstall phpunit/PHPUnit_Selenium

pear install phpunit/PHPUnit

After doing the above and doing just the single install, PHPUnit_Selenium was also auto installed, I'm not sure if this is typical, so some might have to do...

pear install phpunit/PHPUnit_Selenium

Also see http://www.phpunit.de/manual/3.5/en/installation.html for PEAR channel info if needed...

查看更多
我欲成王,谁敢阻挡
5楼-- · 2019-03-24 21:52

I just renamed the file my test was in to "WebTest.php" (the name of the class it contains) and the test runs fine now.

查看更多
登录 后发表回答