1

PHPUnitとSeleniumを初めて使用します。Firefox用のSeleniumIDEプラグインをインストールし、レコーダーを使用していくつかの簡単なテストを作成しました。IDEはデフォルトでテストをHTMLテーブルとしてフォーマットするので、PHPフォーマッターアドオンをSeleniumアドオンにインストールし、テストをPHPUnitフォーマットとしてエクスポートすることができました。次にWindows7に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());
    }
  }

}
?>
4

1 に答える 1

4

Phpunitは、テストケースインスタンスで「 test」で始まるメソッド名を探しています。related_videosメソッドの名前をtest_related_videosに変更すると、検索して実行する必要があります。

于 2012-07-20T18:04:10.373 に答える