TPTP は、Eclipse のワークベンチのコンテキスト外から呼び出すことができる、いくつかの自動化可能サービスを提供します。これらのサービスには、テストの実行、テスト結果の調査、およびテスト結果の公開が含まれます。
このヘルプ・トピックは、組み込み TPTP 自動化可能サービスを使用して、以下のことを行う方法について説明します。
プログラマチックな起動、実行およびテスト結果の生成のために、テスト実行サービスが用意されています。 テスト実行サービスは、既存のテスト実行ハーネス機能を備えています。これに伴い、現在のスタンドアロン・テスト実行ハーネス・メソッドは使用されなくなります。 テスト実行サービスを使用し、Ant スクリプト、シェル・スクリプトおよび任意のプログラムからヘッドレス Eclipse を使用してテストが起動されます。 実行中のマシンに十分なメモリーがある場合、複数のテストを同時に実行することができます (各サービス実行には、現在別々の Eclipse ホスト・インスタンスが必要です)。 テストが TPTP リモート・テスト実行機能およびデプロイメントを使用してリモート・マシン上で稼働している場合でも、Eclipse ホスト・インスタンスを実行するマシンはサービス利用者のマシンです。
サポートされるテスト実行サービスのプロパティーについては、参照資料をご覧ください -- 同じプロパティーが複数のクライアント自動化アダプター間で有効です。 Ant スクリプトでは、サービス・プロパティーの設定およびサービスの実行のために単純な Ant タスクのセットが用意されています。 シェル・スクリプトでは、プロパティーは予測されるコマンド行パラダイムで指定されます (プロパティーにはダッシュを使用し、その後にスペースを続けてインスタンスの値を指定)。 Java プログラムでは、自動化クライアント jar が参照され、プロパティーの設定およびサービス実行の制御に使用されます。 クライアント・アダプターの中には、特定のクライアント環境で必要になる追加オプションを持つものがあります (またはそのアダプターの追加機能として提供されます)。
TPTP の自動可能サービスのコンポーネントは、3 つの jar ファイル、plugin.xml のいくつかの XML、MANIFEST.MF ファイルのいくつかの項目で示される org.eclipse.hyades.execution プラグイン内でパッケージされています。
tptp-automation-client.jar
(サービス・バスのクライアント・サイドの確立に必要な軽量のビットのコードであり、必要な場合に Eclipse を起動し、ヘッドレスにサービスを実行します。この jar は、コマンド行およびシェル・スクリプトからテストを実行するとき、および任意の Java コードからテストを実行するときに参照されます)。tptp-automation-server.jar
(TPTP 自動サーバーであり、サービスがフレームワークを使用して検査および実行されるときにオンデマンドでロードされ、Eclipse アプリケーションの中核の拡張ポイントを実装し、ブローカーおよびサービス・ロケーターとして使用されます。)ant-tptp.jar
(この jar には tptp-automation-client.jar と同じ内容が含まれますが、ほかの Ant タスク・ライブラリーとの整合性を保つように名前変更されています。) 実行中の Eclipse インスタンスの外部でテストが実行される場合、Ant が正しくインストールされていることを確認します。正しいセットアップ方法については、Ant の資料を参照してください。 標準的な Ant のインストールに加えて、ほかのタスクと一緒に ant-tptp.jar を ant lib ディレクトリーにコピーします。 Eclipse 内で実行する場合は、Ant はすでにインストールされています (ただし、Ant 起動構成の「追加タスク」タブまたは「Ant クラスパス」設定にページの「グローバル項目」セクションに ant-tptp.jar が含まれていることを確認してください)。 以下の組み込みサンプル Ant スクリプトは、テスト・プロジェクトのユニット・テスト・フォルダー内で testA というテストを実行する「test.xml」という Ant スクリプトの例です。 テスト・プロジェクトは、指定したワークスペース「d:\development\workspace」に置かれ、Eclipse ホストのインスタンスは「d:\development\eclipse」と指定されます。 プロパティーのその他の有効な組み合わせについては、サポートされるプロパティーの参照リストをご覧ください。
以下の例では TPTP テスト・タスクを使用します (TPTP 自動タスクを使用してテストを実行することも可能です)。より一般的な自動タスクとして、任意の TPTP 自動可能サービスを実行するための Ant タスクがあります。これは、特定の TPTP テスト・タスクと対比されます。 テスト・タスクは、テスト実行サービスの起動のために特別に作成された、タイプが異なっても支障のないテスト・タスクです。 org.eclipse.hyades.execution プラグインの src-automation-client ソース・フォルダーの org.eclipse.hyades.automation.test パッケージ内に、これ以外の Ant スクリプト例が含まれます。
<project name="TPTP Ant Tasks Test Script" default="test" xmlns:tptp="antlib:org.eclipse.hyades.automation.client.adapters.ant"> <property name="eclipse.home" value="D:\development\eclipse"/> <description> This ant script tests the TPTP automation ant task client adapters and also can be used to test the underlying execution of TPTP automatable services via the TPTP automation server </description> <!-- Execute TPTP test suites --> <target name="test" description="Executes TPTP Test Suites using default TPTP Ant Tasks"> <!-- Execute a TPTP test suite using the test task and providing the workspace --> <tptp:test workspace="D:\development\workspace" project="tests" suite="unit-tests/testA.testsuite" synchronicity="synchronous"/> </target> </project>
TPTP 自動化可能サービスを実行できるように Ant を正しく構成しているか確認します
(Ant からのテストの実行に関しては上記のセクションを参照してください)。次の例は、複数のテストを実行するための tptp:execution タスクの使用法と、それらのテスト実行の結果を調査するための tptp:interrogation タスクの使用法を示しています。これらの Ant タスクは両方とも複数の Ant filesets
および/または
filelists
を受け入れます。これにより、ユーザーはワイルドカードを使用したり、タスクへの入力として直接複数のファイルを指定したりすることができます。次の例では、TPTPJUnitTests プロジェクトのすべてのテスト・スイートを実行し、その結果であるすべての .execution ファイルのセットが、提供する Ant 変数の filelist
として戻されます (次の例では、
"tptp.test.results")。次にこの filelist
を入力データとして tptp:interrogation サービスに渡します。サービスはこれらの各実行ファイルを調べ、全体的な判断を決定して、提供する Ant 変数にこれを割り当てます (次の例では、
"tptp.test.verdict")。
<project name="TPTP Automatable Services Tutorial"
default="main" xmlns:tptp="antlib:org.eclipse.hyades.automation.client.adapters.ant"> <!-- Define common properties for all automatable services --> <property name="tptp.test.workspace" value="C:\eclipsecon\eclipse\workspace"/> <property name="tptp.test.project" value="TPTPJUnitTests" /> <property name="tptp.test.connection" value="tptp:rac://localhost:10002/default"/> <property name="tptp.automation.eclipse" value="C:\eclipseconwb_birt\eclipse" />
<!-- Define script-local properties, that vary by installation --> <property name="project.dir" value="${tptp.test.workspace}\${tptp.test.project}"/>
<target name="main" depends="test-execution, test-results-interrogation"/>
<!-- Execute test suites using default results name --> <target name="test-execution"> <echo message="Executing test suite..." /> <tptp:execution resultsrefid="tptp.test.results"> <fileset dir="${project.dir}"> <include name="**/*.testsuite"/> </fileset> </tptp:execution> </target>
<!-- Interrogate test suite results for verdict --> <target name="test-results-interrogation"> <echo message="Interrogating test suite results..." /> <condition property="tptp.test.success"> <tptp:interrogation verdictproperty="tptp.test.verdict"> <filelist refid="tptp.test.results"/> </tptp:interrogation> </condition> <echo message="The overall test result verdict is: '${tptp.test.verdict}'" /> </target>
</project>
TPTP 自動化可能サービスを実行できるように Ant を正しく構成しているか確認します
(Ant からのテストの実行に関しては上記のセクションを参照してください)。次の例は、複数のテストを実行するための tptp:execution タスクの使用法と、それらのテスト結果のレポートに基づいて BIRT を生成するための tptp:publication タスクの使用法を示しています。この公開タスクは、複数の Ant
filesets
および/または filelists
も受け入れます。これにより、ユーザーはワイルドカードを使用したり、入力データとして複数のファイルを直接指定したりすることができます。次の例では、TPTPJUnitTests プロジェクトのすべてのテスト・スイートを実行し、その結果であるすべての .execution ファイルのセットが、提供する Ant 変数の filelist
として戻されます (次の例では、
"tptp.test.results")。次にこの filelist
を入力データとして tptp:publication サービスに渡します。サービスは、デフォルトのレポート・テンプレート (org.eclipse.tptp.test.report.birt プラグインにある TestExecution.rptdesign) を使用して TPTP 実行レポートを生成し、これを、指定された場所 (この場合は c:\temp\report.html) に置きます。
<project name="TPTP Automatable Services Tutorial"
default="main" xmlns:tptp="antlib:org.eclipse.hyades.automation.client.adapters.ant"> <!-- Define common properties for all automatable services --> <property name="tptp.test.workspace" value="C:\eclipsecon\eclipse\workspace"/> <property name="tptp.test.project" value="TPTPJUnitTests" /> <property name="tptp.test.connection" value="tptp:rac://localhost:10002/default"/> <property name="tptp.automation.eclipse" value="C:\eclipseconwb_birt\eclipse" />
<!-- Define script-local properties, that vary by installation --> <property name="project.dir" value="${tptp.test.workspace}\${tptp.test.project}"/> <property name="report.publication.location" location="c:/temp" />
<target name="main" depends="test-execution, test-results-publication"/>
<!-- Execute test suites using default results name --> <target name="test-execution"> <echo message="Executing test suite..." /> <tptp:execution resultsrefid="tptp.test.results"> <fileset dir="${project.dir}"> <include name="**/*.testsuite"/> </fileset> </tptp:execution> </target>
<!-- Publish test suite results report -->
<target name="test-results-publication"> <echo message="Publishing test suite results report..." /> <tptp:publication report="${report.publication.location}/report.html"> <filelist refid="tptp.test.results"/> </tptp:publication> </target>
</project>
別の BIRT レポート・テンプレートを指定して tptp:publication タスクの振る舞いをカスタマイズすることもできます (例えば、プラグイン org.eclipse.tptp.test.report.birt のテンプレート・ディレクトリーにある TabularReport.rptdesign など)。また、テスト実行結果ファイルの代わりに公開テスト・スイートの公開サービスを使用し、このテスト・スイートを入力データとして公開サービスに提供することにより、振る舞いをカスタマイズすることもできます。公開テスト・スイート公開サービスを使用し、テスト・スイート・ファイルを入力データとして公開サービスに渡す場合は、レポート・ウィンドウ (ワークスペースを照会してその時間内のすべての実行結果を検索するために使用されるウィンドウ) の開始日と終了日も指定する必要があります。次の例では、過去 60 日間の各実行結果を選択し、表形式レポート設計を使用してレポートを生成して、Test1 プロジェクトのすべてのテスト・スイートに関するレポートを実行する方法を示しています。
<project name="TPTP Automatable Services Tutorial"
default="main" xmlns:tptp="antlib:org.eclipse.hyades.automation.client.adapters.ant"> <!-- Define common properties for all automatable services --> <property name="tptp.test.workspace" value="C:\eclipsecon\eclipse\workspace"/> <property name="tptp.test.project" value="TPTPJUnitTests" /> <property name="tptp.test.connection" value="tptp:rac://localhost:10002/default"/> <property name="tptp.automation.eclipse" value="C:\eclipseconwb_birt\eclipse" />
<!-- Define script-local properties, that vary by installation --> <property name="project.dir" value="${tptp.test.workspace}\${tptp.test.project}"/> <property name="report.publication.location" location="c:/temp" /> <property name="tptp.publication.service" value="org.eclipse.tptp.test.report.birt.publish-testsuites"/>
<!-- Run the report --> <target name="main" depends="test-results-publication"/>
<target name="set-date-range"> <!-- Use standard ant tstamp mechanisms to specify the desired date range --> <!-- This example uses a range between today and 60 days days prior --> <tstamp> <format property="startDateTime" pattern="MM/dd/yyyy hh:mm aa" offset="-60" unit="day"/> </tstamp> <tstamp> <format property="endDateTime" pattern="MM/dd/yyyy hh:mm aa"/> </tstamp> </target>
<!-- Publish test suite results report --> <target name="test-results-publication" depends="set-date-range"> <echo message="Publishing test suite results report..." /> <tptp:publication report="${report.dir}/report.html" reportTemplateLocation="C:\TPTP_TestPass\ReportBuild\eclipse\plugins\org.eclipse.tptp.test.report.birt_4.2.0.v200605180959\templates\TabularReport.rptdesign" startDateTime="${startDateTime}" endDateTime="${endDateTime}" > <fileset dir="${project.dir}"> <include name="**/*.testsuite" /> </fileset> </tptp:publication> </target>
</project>
テストは、コマンド行およびシェル・スクリプトから、コマンド行引数の形のテスト・プロパティーを使用して直接実行することができます。 TPTP 自動クライアント・アダプターでは、Windows 内での使用には .bat および .cmd ファイルが、Linux オペレーティング・システム内での使用には .sh ファイルがそれぞれ提供されています。長形式の引数のセットおよび/または頻繁に繰り返される引数を構成ファイル内で指定し、テスト実行サービスをコマンド行から実行するのに必要な入力数を最小化することができます。 シェル自動クライアント・アダプターは、テキスト・ファイル (バッチ・ファイル用またはスクリプト用の) および補足的な Java コンポーネントとして存在しています -- コマンド行からテストを実行するには、これらの両方が必要です。 TPTP 提供のすべての自動クライアント・アダプターは tptp-automation-client.jar から見つけることができます。ただし、ant-tptp.jar は ant jar 形式でアダプター・コードのいくつかを複製します (これは、ほかの使用可能な Ant タスクで一貫して指定されてきた TPTP タスク jar を保持する目的で行われます)。
テスト実行サービスのプロパティーは、プロパティー名にハイフンを付けてプレフィックシングすることで設定されますが、この時 Eclipse のホーム・ディレクトリーまたはルート・ディレクトリーを指定することも忘れずに行ってください。
テストは任意の Java アプリケーションから起動することができます。また、Ant アダプターやシェル・アダプターのようなほかのクライアント自動アダプターでは Java アダプターを内部で使用し、サービス・バスに接続します。 特定の Java コードからテストを実行する際に唯一要求されるのは、tptp-automation-client.jar が正しく参照されるか (Eclipse では、これは Java プロジェクトのビルド・パス上にライブラリーを置くことを意味します)、またすべての標準的な TPTP 要件 (Agent Controller が実行されていなければならないなど) が適用されるかということです。
Java 自動クライアント・アダプターでは、すべての指定可能なプロパティーが標準 Java プロパティーのオブジェクトに含まれた形でテストを実行するための、非常にシンプルな API を提供しています。 以下の例は、直前の Ant スクリプト例で紹介したものと同じテストの実行例です。 実行メソッドに渡されるサービス ID は、TPTP テスト実行サービスの ID であることに注意してください (このサービスではすべての基本 TPTP テスト・タイプがサポートされています)。ほかの自動サービスを実行することもできますが、次のコードで構成される ID およびプロパティーは変更する必要があります。
// Create the Java adapter associated with the specified Eclipse home AutomationClientAdapter automation = new AutomationClientAdapter ("d:\\development\\eclipse"); // Create and configure a properties object Properties properties = new Properties(); properties.setProperty("workspace", "D:\\development\\workspace"); properties.setProperty("project", "tests"); properties.setProperty("suite", "unit-tests/testA.testsuite"); // Execute the service named below using the configured properties automation.execute("org.eclipse.hyades.test.tools.core.execute", properties);
関連タスク
スクリプトとアプリケーションからテストを起動
(C) Copyright IBM Corporation 2005,2006. All Rights Reserved