setBrowser-6ren">
gpt4 book ai didi

php - PHPUnit Selenium 测试用例的代码覆盖率

转载 作者:行者123 更新时间:2023-12-03 01:50:44 25 4
gpt4 key购买 nike

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

<?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");
}
}
?>

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

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

Cookie 生命周期已设置 session ,即意味着在测试用例执行后,此 Cookie 将不再可用,并且当我尝试启动 phpunit_coverage.php 时,它无法找到 Cookie 和信息,因此不会出现代码覆盖。

我不明白的事情:

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

我在很多论坛上都看到过这个问题,但有一个给出了具体的答案

许多论坛建议使用localhost而不是127.0.0.1作为服务器名称。就我而言,它已经是本地主机。

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

谢谢,拉乌里

最佳答案

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

关于php - PHPUnit Selenium 测试用例的代码覆盖率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10836121/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com