Jtest でプロジェクトを解析するには、Ant は特定の順序で次の処理を実行する必要があります。
コードに対して静的解析を実行するには、次の操作を行います。
-listener スイッチを使用してコマンド ラインに Parasoft リスナーを追加するか、ターゲットで jtest:listener タスクを設定します。Ant でプロジェクトをビルドします。コマンドは次のようになります。
ant -lib PATH/TO/jtest-ant-plugin.jar -listener com.parasoft.Listener myTarget |
上記のサンプルでは、コマンド ラインに Jtest Plugin for Ant が追加されていますが、JAR ファイルを Ant の lib ディレクトリにデプロイすることもできます(「初期セットアップ」を参照)。
デフォルトでは、テスト ソースは解析から除外されます。テスト コードを解析対象にするには、
excludeTestSources オプションを無効にします。「Ant 用 Jtest ゴール リファレンス」を参照してください。
Jtest レポートに単体テストの結果を含めるには、jtest タスクと agent タスク、および単体テスト用のビルトイン テスト コンフィギュレーション Unit Tests を使用してテストを実行します。
Unit Tests ビルトイン テスト コンフィギュレーション-listener スイッチを使用してコマンド ラインに Parasoft リスナーを追加するか、ターゲットで jtest:listener タスクを設定します。Ant でプロジェクトをビルドします。コマンドは次のようになります (カバレッジの収集を省略するには、jtest.coverage.skip オプションを使用します)。
ant -lib PATH/TO/jtest-ant-plugin.jar -listener com.parasoft.Listener buildTestAnalyze |
デフォルトでは、Jtest は実行されたテストのカバレッジ データを収集します。カバレッジの収集を無効化するには、jtest.coverage.skip オプションを有効にします (詳細は「Ant 用 Jtest タスク リファレンス」を参照)。
agent タスクJtest でカバレッジ データを収集する場合、Java エージェントを使用するのが推奨される方法です。(.class ファイルを変更せずに) 実行時バイトコードのインストゥルメンテーションを行うことができる agent タスクを適切なターゲットに設定します。次のサンプルは、必要なタスクを 1 つのターゲットで設定したビルド スクリプトを示しています。
<project name="agent-sample" default="buildTestAnalyze" xmlns:jtest="antlib:com.parasoft.jtest.plugin.ant">
<!-- sources directory containing both tests and application source code. Usually these sources are not placed in one directory. -->
<property name="sources" value="src"/>
<!-- classes directory -->
<property name="classes" value="bin"/>
<target name="buildTestAnalyze">
<!-- compiling sources -->
<javac srcdir="${sources}" destdir="${classes}"/>
<!-- instrumenting bytecode -->
<!-- run tests -->
<jtest:agent>
<!-- Following attributes will be set: haltonerror="no" haltonfailure="no" fork="yes"
If agent task skipped nested task will be executed without any config changes. -->
<junit>
<!-- Formatter element will be set as following: <formatter type="xml"/>
If different formatter type has been set it will get overridden.
If formatter has been configured by classname it will be left as it is. -->
<classpath>
<pathelement location="${classes}"/>
</classpath>
<batchtest>
<fileset dir="${classes}" includes="**/*Test.class"/>
</batchtest>
</junit>
<coverage>
<includes>
<fileset dir="${classes}" />
</includes>
<testIncludes>
<include>**/*Test.class</include>
</testIncludes>
</coverage>
</jtest:agent>
<!-- analysis -->
<jtest:jtest/>
</target>
</project> |
Jtest のカバレッジ エージェントを使用すると、実行中のアプリケーションでの手動テストまたは自動テスト実行時にカバレッジ データを収集できます。Jtest でのアプリケーション カバレッジの収集については「アプリケーション カバレッジ」を参照してください。
以下のいずれかの方法でカバレッジを無効にできます。
skip パラメータを指定してカバレッジの収集をスキップします (この方法では、Jtest の実行は無効化されません)。-D オプションを指定して Ant を実行します。-Djtest.skip=true<property name="jtest.skip" value="true"/> ( Jtest タスクがサブプロジェクトで構成されている場合、このプロパティを継承していることを確認してください)。