JUnit XML フォーマットは、テスト自動化フレームワークや CI ツールがテスト結果を保存し、共有するのに広く使われている方法の 1 つです。
TestRail CLI は以下のことができます。
-
- JUnit XML レポートの読み込み
- JUnit XML レポートの内容を TestRail エンティティ (スイート、セクション、ケース、結果) に変換する
- TestRail API を使用して TestRail に JUnit XML レポートをインポートする
このガイドでは、以下を説明します。
-
- JUnit XML を TestRail にマッピングする方法
<testsuite>および<testcase>タグの処理方法- TestRail 用の JUnit XML ファイルでカスタム プロパティを使用する方法
case_results_statusesを使用して自動テストの結果をカスタム ステータスにマッピングする方法
JUnit レポートのサンプル
JUnit レポート フォーマットは、テスト自動化フレームワークや CI ツールがテスト結果を保存し、視覚化するのに広く使われています。TestRail CLI はレポートを解析し、要素を TestRail エンティティに変換します。それらのエンティティは API によってインポートされます。下記は標準的な JUnit レポートのサンプルです。
<testsuites name="test suites root">
<testsuite failures="0" errors="0" skipped="1" tests="1" time="3049" name="tests.LoginTests">
<properties>
<property name="setting1" value="True"/>
<property name="setting2" value="value2"/>
</properties>
<testcase classname="tests.LoginTests" name="test_case_1" time="159">
<skipped type="pytest.skip" message="Please skip">skipped by user</skipped>
</testcase>
<testcase classname="tests.LoginTests" name="test_case_2" time="650">
</testcase>
<testcase classname="tests.LoginTests" name="test_case_3" time="121">
<failure type="pytest.failure" message="Fail due to...">failed due to...</failure>
</testcase>
</testsuite>
</testsuites>
JUnit タグから TestRail へのマッピング
次の表に示すように、TestRail CLI によって Junit レポート タグが解析され、TestRail エンティティに変換されます。
| XML JUnit タグ | TestRail でのマッピング |
|---|---|
<testsuites> |
テスト スイート |
<testsuite> |
セクション |
<testcase> |
テスト ケース |
JUnit の <testsuite> の処理
<testsuite> タグが付いた要素は、TestRail のセクションに変換され、プロパティが TestRail のテスト ランの説明に追加されます。下に <property> 子タグを持つ <testsuite> のサンプルを示します。
<testsuites name="test suites root">
<testsuite failures="0" errors="0" skipped="1" tests="1" time="3049" name="tests.LoginTests">
<properties>
<property name="setting1" value="True"/>
<property name="setting2" value="value2"/>
</properties>
(...)
</testsuite>
</testsuites>
| 属性またはタグ | TestRail でのマッピング |
|---|---|
name |
セクション名 |
<property> |
プロパティ名および値が連結され、テスト ランの説明に追加されます。 |
JUnit の <testcase> の処理
<testcase> タグが付いた要素は TestRail のテスト ケースとそのテスト結果に変換されます。
| 属性 | TestRail でのマッピング |
|---|---|
name |
テスト ケース名 |
time |
テスト結果の経過時間です。 |
-
- 各
<testcase>は、テスト結果 を持つ TestRail のテスト ケースとしてインポートされます。 - 結果のステータスは子タグによって決定されます。
- 各
タグがない場合、テスト結果は Passed になります。<failure> タグがある場合、テスト結果は Failed になり、<skipped> タグがある場合、テスト結果は Retest になります。下の表はサンプルを示しています。
| XML 構造 | TestRail のステータス |
|---|---|
<testcase classname="tests.LoginTests" name="test_case_1" time="135"> </testcase> |
Passed |
<testcase classname="tests.LoginTests" name="test_case_1" time="135">
<failure type="errorType" message="Failure message">
Error (stacktrace)
</failure>
</testcase>
|
Failed |
<testcase classname="tests.LoginTests" name="test_case_1" time="135">
<skipped type="skipType" message="Skip test">
Test skipped by user
</skipped>
</testcase>
|
Retest |
属性のデータと、<failure> および <skipped> タグのテキストが下記のフォーマットでテスト結果のコメントに追加されます。
Type: errorType Message: Failure message Text: Error (stacktrace)
<property>を使用したカスタム テスト データの追加
特別なプロパティ名を使って、追加フィールド、手順、コメント、添付ファイル を追加できます。サポートされるプロパティとその意味は、下の表に示されています。
| 名前 | TestRailでのマッピング |
|---|---|
testrail_case_field |
テストケースフィールド(field_name:field_value) |
testrail_result_field |
テスト結果フィールド(field_name:field_value) |
testrail_result_comment |
テスト結果のコメントにテキストを追加します |
testrail_result_step |
ステップとステータスを追加します(passed,failed,untested) |
testrail_attachment |
テスト結果に添付ファイルをアップロードします(最大 256 MB) |
以下は、上記のすべてのフィールドを含むレポートの例です。これらのプロパティの使用方法の詳細は、TestRail CLI 使用例ページを参照してください。
<testsuites name="test suites root">
<testsuite failures="0" errors="0" skipped="1" tests="1" time="3049" name="tests.LoginTests">
<testcase classname="tests.LoginTests" name="test_case_1" time="650">
<properties>
<property name="testrail_case_field" value="custom_preconds:My preconditions"/>
<property name="testrail_case_field" value="type_id:3"/>
<property name="testrail_result_field" value="version:1.1"/>
<property name="testrail_result_field" value="custom_field:custom_value"/>
<property name="testrail_result_step" value="passed: Insert login credentials"/>
<property name="testrail_result_step" value="failed: Click submit"/>
<property name="testrail_result_step" value="untested: User should be logged in"/>
<property name="testrail_result_comment" value="Finding 1"/>
<property name="testrail_result_comment" value="Finding 2"/>
<property name="testrail_attachment" value="path_to/logs.log"/>
<property name="testrail_attachment" value="path_to/screenshot.jpg"/>
</properties>
</testcase>
</testsuite>
</testsuites>
要点
-
- JUnit XML は自動テストの結果を表すための汎用的なフォーマットです。
- TestRail CLI は、JUnit XML をスイート、セクション、ケース、結果として TestRail にインポートします。
- case_results_statuses は、自動テストのステータスと TestRail のワークフローの整合性を確保します。
- カスタム プロパティ を使用すると、コンテキスト、手順、および添付ファイルを追加して結果を拡張できます。
次のステップ
-
- GitHubの Cypress-saucectlサンプルプロジェクト をチェックして、実践的なサンプルを参照します。
- その他のパラメーターについては、TestRail CLI のマニュアルを参照してください。
- チームの GitHub や TestRail のサポートを通じて、改善の提案や質問を行います。
