如何解决此错误:“找不到类 PHPUnit_Extensions_SeleniumTestCase”

发布于 2024-07-05 13:07:59 字数 719 浏览 6 评论 0原文

我正在尝试使用 phpunit 运行 SeleniumTestCase,但无法让它使用 phpunit.bat 脚本运行。

我的目标是在 CruiseControl 和 Selenium RC 中使用 phpunit。 php在控制下。 测试如下:

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');
    }
}

我还在 include_path 中安装了 PEAR,并使用 Selenium 扩展安装了 PHPUnit。 我用 pear 安装程序安装了这些,所以我想这不是问题。

任何帮助将非常感激。

谢谢,雷米

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(10

执笏见 2024-07-12 13:07:59

我发现 PHPUnit 教程中的以下示例可以正常工作,而我编写的测试中却出现了相同的错误。
解决方案令人惊讶。 确保您的类位于 块内,而不是 脚本中的块。

<?php
require_once 'PHPUnit/Framework.php';

class StackTest extends PHPUnit_Framework_TestCase
{
    public function testPushAndPop()
    {
        $stack = array();
        $this->assertEquals(0, count($stack));

        array_push($stack, 'foo');
        $this->assertEquals('foo', $stack[count($stack)-1]);
        $this->assertEquals(1, count($stack));

        $this->assertEquals('foo', array_pop($stack));
        $this->assertEquals(0, count($stack));
    }
}
?>

I found that the following sample from PHPUnit tutorial was working while the same error appeared in the test that I had written.
The solution was a surprise. Ensure that your class is inside a <?php .. ?> block and not a <? .. ?> block in the script.

<?php
require_once 'PHPUnit/Framework.php';

class StackTest extends PHPUnit_Framework_TestCase
{
    public function testPushAndPop()
    {
        $stack = array();
        $this->assertEquals(0, count($stack));

        array_push($stack, 'foo');
        $this->assertEquals('foo', $stack[count($stack)-1]);
        $this->assertEquals(1, count($stack));

        $this->assertEquals('foo', array_pop($stack));
        $this->assertEquals(0, count($stack));
    }
}
?>
笑梦风尘 2024-07-12 13:07:59

这是我解决这个问题的方法:

  1. 确保安装了 php 的curl扩展,
    例如,对于 ubuntu sudo apt-get install php5-curl
  2. 输入 sudo pear install phpunit/PHPUnit_Selenium

之后,您应该安装了缺少的文件

快乐编码...

Here is how i solved this problem:

  1. Make sure that curl extension for php is installed,
    e.g for ubuntu sudo apt-get install php5-curl
  2. Enter sudo pear install phpunit/PHPUnit_Selenium

After that you should have the missing file installed

Happy coding...

拧巴小姐 2024-07-12 13:07:59

尝试:

class WebTest extends \PHPUnit_Extensions_Selenium2TestCase

这可能是命名空间问题,就像我一样。

Try:

class WebTest extends \PHPUnit_Extensions_Selenium2TestCase

It can be namespace issue, as it was for me.

岁吢 2024-07-12 13:07:59

好吧,当我使用内联命令时:如果从 PhPunit 目录启动测试,则在从测试目录启动它时出现错误,我没有错误......

但我仍然没有任何对 selenium 服务器的访问权限......我应该有是否先启动它。

如果是,很奇怪我们没有指定 PhPUnit 的任何句柄......

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

叹梦 2024-07-12 13:07:59

当它失败时,它并不总是打印出最详细的错误消息。

始终记住在运行测试之前也启动 Selenium。

java -jar selenium-server-standalone-2.39.0.jar

这是为我自己工作的代码示例。 http://www.siteconsortium.com/h/p1.php?id=php002 。 显然,有很多不同的方法来编写测试套件并启动测试用例,但我首先使用 set_class_path 来消除类问题。

When it fails it doesn't always print out the most verbose error messages.

Always remember to start Selenium too prior to running test.

java -jar selenium-server-standalone-2.39.0.jar

Here is an example of code that was working for myself. http://www.siteconsortium.com/h/p1.php?id=php002. Obviously there are a lot of different way to write the test suite, and launch the test case but I used the set_class_path to get rid of class issues at first.

靖瑶 2024-07-12 13:07:59

不要认为 pear 安装没有问题。

我已经通过 pear 安装了 phpunit,但是尽管当我查看文件夹内部时它说安装顺利,但我有所有以 .tmp 开头的文件,例如 PHPUnit/Util/.tmpErrorHandler.php ,所以当我第一次运行测试时很自然时间它给了我与上面相同的错误。 在检查确实该文件不存在之后,我手动将 PHPUnit 安装到与 pear 相同的文件夹中,唉,一切都很好。 我在Mac/leopard。

关于 Selenim RC 不要忘记在终端中运行来启动它
java -jar /path/to/file/selenium-server.jar

Do not presume that the pear install occurred without problems.

I had installed phpunit through pear but despite it saying the install went fine when I looked inside the folder, I had all these files starting with .tmp, eg PHPUnit/Util/.tmpErrorHandler.php so naturally when i ran a test for the 1st time it gave me the same error as above. After checking that indeed the file wasn't there I did a manual install of PHPUnit to the same folder as pear and alas, all was fine. I'm in Mac/leopard.

About Selenim RC don't forget to start it by running in terminal
java -jar /path/to/file/selenium-server.jar

瞄了个咪的 2024-07-12 13:07:59

我刚刚将测试所在的文件重命名为“WebTest.php”(它包含的类的名称),测试现在运行良好。

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.

笨死的猪 2024-07-12 13:07:59

看一下 php 手册中 require_once 条目中的注释之一。

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

“require_once(和 include_once 对于这一点)很慢

此外,如果您计划使用单位测试和模拟对象(即在要测试的类中包含真实类之前包括模拟类),它将不起作用,因为 require() 加载的是文件而不是类。”

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."

还在原地等你 2024-07-12 13:07:59

希望这是比此处给出的更明确的答案(这没有解决我的问题)。 如果您收到此错误,请检查您的 PEAR 文件夹并查看“SeleniumTestCase.php”文件是否确实存在:

/PEAR/PHPUnit/Extensions/SeleniumTestCase.php

如果不存在,最简单的方法是使用 PEAR 卸载并重新安装 PHPUnit ...

pear uninstall phpunit/PHPUnit

pear uninstall phpunit/PHPUnit_Selenium

pear install phpunit/PHPUnit

执行上述操作后并且只进行单个安装,PHPUnit_Selenium 也会自动安装,我不确定这是否典型,所以有些人可能必须这样做...

pear install phpunit/PHPUnit_Selenium

另请参阅 http://www.phpunit.de/manual/3.5/en/installation.html 获取 PEAR 频道信息(如果需要)...

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

短暂陪伴 2024-07-12 13:07:59

处理方法如下:

如果遇到“在(测试用例文件名)中找不到类 PHPUnit_Extensions_SeleniumTestCase”问题,则必须执行以下两件事:

1. 将测试用例文件重命名为其包含的类的名称
2. 您应该从测试文件夹中启动 phpunit。

这应该可以解决您的问题。

安德鲁

Here is the deal:

If you have a "Class PHPUnit_Extensions_SeleniumTestCase could not be found in (testcase file name)" problem, you have to do the following two things:

1. Rename the file of test case to the name of the class it contains
2. You should launch phpunit from the folder with your tests.

This should fix your problem.

Andrew

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文