为什么我的PHPUnit测试不起作用?

时间:2012-07-20 17:57:07

标签: php selenium phpunit qa

首次使用PHPUnit和Selenium。安装了适用于Firefox的Selenium IDE插件,使用录像机创建了一些简单的测试。 IDE默认将测试格式化为HTML表格,因此我将PHP格式化程序插件安装到Selenium插件中,并能够将测试导出为PHPUnit格式。接下来在Windows 7上安装了PHPUnit。还为PHPUnit安装了Selenium插件。

然后使用此命令运行我的测试:

phpunit Mytests.php

输出是:

Time: 0 seconds, Memory: 2.7Mb
OK (0 tests, 0 assertions)

非常棒没有错误,但看起来测试也没有。怎么了?它是我的测试文件的内容:

<?php

require_once 'PEAR/PHPUnit/Extensions/SeleniumTestCase.php';

class Mytests extends PHPUnit_Extensions_SeleniumTestCase
{
  protected function setUp()
  {
    $this->setBrowser("*chrome");
    $this->setBrowserUrl("http://www.foobar.com/");
  }

  public function related_videos()
  {
    // // make sure there are 4 related items
    $this->open("/");
    $this->click("xpath=//div[contains(@id, 'featured')]/article/div/a[contains(@class,'thumb')]");
    $this->waitForPageToLoad("30000");
    try {
        $this->assertEquals("4", $this->getXpathCount("//descendant-or-self::*[@id = 'related']/descendant::article"));
    } catch (PHPUnit_Framework_AssertionFailedError $e) {
        array_push($this->verificationErrors, $e->toString());
    }
  }

}
?>

1 个答案:

答案 0 :(得分:4)

Phpunit在testcase实例上寻找方法names starting with "test",如果你将related_videos方法重命名为test_related_videos它应该找到并运行它。

相关问题