2012-07-20 28 views
1

第一次使用PHPUnit和Selenium。安装了Firefox的Selenium IDE插件,使用录像机创建了一些简单的测试。 IDE默认将测试格式设置为HTML表格,因此我将PHP格式化插件安装到了Selenium插件,并且能够将测试作为PHPUnit格式导出。接下来在Windows 7上安装了PHPUnit。还为PHPUnit安装了Selenium插件。为什么我的PHPUnit测试不工作?

然后跑使用这个命令我测试:

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

} 
?> 

回答

4

的PHPUnit正在寻找在测试用例实例方法names starting with "test",如果重命名related_videos方法test_related_videos它应该找到并运行它。

+0

做到了,谢谢! – TK123 2012-07-20 18:09:15

+0

虽然现在输出是'好的,但不完整或跳过测试!测试:1,断言:0,跳过:1'。测试不会在我的电脑上启动Chrome,您是否也知道它为何被跳过? – TK123 2012-07-20 18:12:38

+0

确定使用--verbose标志运行该命令显示该问题。 PHPUnit无法连接到Selenium服务器。关闭以解决那个叹息。 – TK123 2012-07-20 18:27:32

相关问题