2007年9月13日木曜日

tapestry-test なんとなく邦訳

Selenium!?と思って読みたかったが、超参考にさせていただいているhttp://kuramo.ch/氏のサイトにjaなページが無かったので、投げやりな訳をつけてみました。なんとなく、こんな風に理解しました、という程度なので決して参考にしないでください。サンプルソースを見ると、見覚えのあるメソッドが書かれてますが、フレームを使った場合とか、waitForLoad()はそもそもうまく動作するのか、とか気になります。

Tapestry Test Utilities

This library is just a couple of base classes to make it easier to build integration test suites around Selenium. This library is currently based on Selenium 0.8.1. The strategy is to start, in process, a Selenimum Server (which, in turn, starts and manages a web browser), a Jetty instance (for the web browser to talk to), and a Selenium client (which talks to the server). The client is able to request URLs, fill in form data, click links, and make assertions about output and behavior.

Tapestry Test Utilities

このライブラリは、Seleniumでの統合テスト一式の構築を簡単にするためのわずかな基底クラスです。 このライブラリは現在はSelenium0.8.1を元にしています。 WebBrowserを開始して管理するためのSelenimum Server、WebBrowserと通信するJettyのインスタンス、そしてWebServerと通信するSelenium Client、という順に開始するという仕組みです。(適当、なんとなくこんな風な理解でよいと思う)

Usage and Configuration

The core part of this library is a base class for you to extend your tests cases from: AbstractIntegrationTestSuite. This class is responsible for starting an instance of Jetty to server your web application, as well as a copy of Selenium Server. It also implements the Selenium interface. You must inform the suite about the location of your web application. The default location is src/main/webapp (as this is the default directory for storing a web application when building using Maven). This can be changed by provided a public constructor for your test suite.

使用方法とその設定方法

このライブラリのコアは、TestCaseを継承するための基底クラス「AbstractIntegrationTestSuite」です。 このクラスはWebApplicationサーバのJettyのインスタンス、Selenium Server を開始する事を担当します。それはSelenium Server の interface を実行する事と同様です。 WebApplicationの場所についての一式(パッケージ?)を知らせる必要があります。defaultの場所は「src/main/webapp(これはMavenを使ってbuildする場合のWebApplicationの補完のためのdefaultディレクトリ)」です。 これはTestSuiteのpublicなコンストラクタで変更することができます。
Here's an example from one of the Tapestry modules:
以下にTapestryモジュールの一例を示します。
package org.apache.tapestry.spring;
import org.apache.tapestry.test.AbstractIntegrationTestSuite;
import org.testng.annotations.Test;
public class TapestrySpringIntegrationTest extends AbstractIntegrationTestSuite
{
    public TapestrySpringIntegrationTest()
    {
        super("src/test/webapp");
    }
    @Test
    public void integration_test() throws Exception
    {
        open(BASE_URL);
        type("input", "paris in the springtime");
        clickAndWait("//input[@value='Convert']");
        assertFieldValue("input", "PARIS IN THE SPRINGTIME");
    }
    @Test
    public void access_to_spring_context() throws Exception
    {
        open(BASE_URL);
        assertTextPresent("[upcase]");
    }
}
This is a very simple example, and demonstrates a mix of Selenium methods (such as open() and type()) and methods added by the AbstractIntegrationTestSuite base class (clickAndWait() and assertFieldValue()). Of course, a real integration test would contain many methods, and may need to single thread their execution, or even specify an execution order. In addition, the AbstractIntegrationTestSuite base class extends the normal exception reporting provided by Selenium; when a failure occurs inside Selenium server, a more detailed message, including the current page's HTML source, is reported to System.err.
これはとても単純な例で、いくつかのちょっとしたSeleniumの機能(open()とtype()のような)と、AbstractIntegrationTestSuite基底クラスで追加された機能(clickAndWait()とassertFieldValue())を組み合わせたデモンストレーションです。 もちろん、実際の統合テストはもっとたくさんの機能を含んでおり、それらはSingleThreadでの実行だったり、実行順が指定されたりするかもしれません。 AbstractIntegrationTestSuite基底クラスは、Seleniumにより提供される通常のExceptionの記録を拡張します。 SeleniumServer内で失敗が起こった時、現在のHTMLページのソースを含む、より詳細なメッセージが標準エラー出力に記録されます。

0 件のコメント: