PHPUnitSeleniumTestcase的代码覆盖率

Sum*_*man 12 php selenium code-coverage

我已经为PHP编写了Selenium Test case.我想在执行这些测试用例时获得代码覆盖率.我的测试用例:

<?php
class Example extends PHPUnit_Extensions_SeleniumTestCase
{
  protected $coverageScriptUrl = 'http://applicationname/phpunit_coverage.php';

  protected function setUp()
  {
    $this->setBrowser("*firefox");
    $this->setBrowserUrl("http://applicationname");
    $this->setCollectCodeCoverageInformation(true);
    $this->setTestId("10001");
    $this->setHost("applicationname");
  }

  public function testMyTestCase()
  {
    $this->open("http://applicationame");
    $this->assertEquals("title", $this->getTitle());
    $this->type("id=ext-comp-1002", "testuser");
    $this->fireEvent("id=ext-comp-1002", "blur");
    $this->type("id=ext-comp-1003", "testpassword");
    $this->fireEvent("id=ext-comp-1003", "blur");
    $this->click("ext-gen45");
    $this->waitForPageToLoad("200000");
}
}
?>
Run Code Online (Sandbox Code Playgroud)

我已按照链接"http://www.phpunit.de/manual/current/en/selenium.html"中提到的步骤进行操作

运行测试后,我无法找到代码覆盖率.在phpunit_coverage.php中,它正在查找名为PHPUNIT_SELENIUM_TEST_ID的cookie.这个cookie是在Driver.php中创建的,我看到cookie可用,但是它的主机名设置为"localhost"而不是我的应用程序名称.

Cookie生活时间设置为会话,即在测试用例执行后立即意味着此cookie将不再可用,当我尝试启动phpunit_coverage.php时,它无法找到cookie和信息,因此不会出现代码覆盖.

我不明白的事情:

  1. protected $coverageScriptUrl = 'http://applicationname/phpunit_coverage.php';
  2. 如果cookie具有除应用程序之外的不同主机,则此cookie可以访问

我已经看到很多论坛都在讨论这个问题,但是有人给出了具体的答案

许多论坛建议使用localhost而不是127.0.0.1服务器名称.在我的情况下,它已经是localhost.

这方面的任何建议都会有所帮助.

谢谢,拉武里

小智 2

Selenium 的集成或功能测试不涵盖代码,因为它们涵盖行为。像这样的测试的代码覆盖率报告不会生成任何有用的信息。单元测试将生成更有意义的代码覆盖率报告。测试是根据 Selenium 提供和来自 Selenium 的信息运行的,可以这么说,它并不是真正测试您的“代码”。