ページを選択

テスト結果のインポート

TestRail でテスト結果を中央管理するのは有力なユース ケースです。そうすると、すべてのテスト作業を 1 箇所に統合し、テストをより詳細に可視化および管理できるほか、TestRail が提供する豊富なテスト レポートの中から任意のレポートを生成できます。

プログラム的にテスト ランを作成し、結果をインポートする機能を利用すると、以下のような統合が可能です。

    • テスト ランを作成し、テスト自動化スイートから結果をアップロードします。
    • アウトソースされたテスト結果でテスト ランを更新します。
実際のサンプル ユース ケース
TestRail CLI テスト自動化レポートからのテスト ランの作成と結果のアップロード
Functionize 自動化されたテストからのテスト ランの作成と結果のアップロード
Katalon 自動化されたテストからのテスト ランの作成と結果のアップロード
Global App Testing 外部のテスターによって追加された結果のサブミット

テスト ランの作成

テスト ランは、実行するテストのコンテナーとなり、結果をサブミットすることを可能にします。単純なテスト ランを追加するには、次のエンドポイントを使用します。

リクエスト

POST  index.php?/api/v2/add_run/{project_id}

curl -X POST \ 
  -u "user@example.com:password" \ 
  -F "@path/to/data.json" \ 
  "https://example.testrail.io/index.php?/api/v2/add_run/12"

リクエスト ボディのサンプル

{
    "suite_id": 1,
    "name": "New test run",
    "description": "Test run description",
    "assignedto_id": 5,
    "include_all": false,
    "case_ids": [4076, 4078, 4079]
}

レスポンス ボディのサンプル

{
    "id": 228,
    "suite_id": 53,
    "name": "New test run",
    "description": "Test run description",
    "milestone_id": null,
    "assignedto_id": 5,
    "include_all": false,
    "is_completed": false,
    "completed_on": null,
    "config": null,
    "config_ids": [],
    "passed_count": 0,
    "blocked_count": 0,
    "untested_count": 3,
    "retest_count": 0,
    "failed_count": 0,
    "custom_status1_count": 0,
    "custom_status2_count": 0,
    "custom_status3_count": 0,
    "custom_status4_count": 0,
    "custom_status5_count": 0,
    "custom_status6_count": 0,
    "custom_status7_count": 0,
    "project_id": 27,
    "plan_id": null,
    "created_on": 1684936873,
    "updated_on": 1684936873,
    "refs": null,
    "dataset_id": null,
    "created_by": 18,
    "url": "https://marketing80testing.testrail-staging.com/index.php?/runs/view/228"
}

ケース ID を使用したテスト ランへの結果の追加

テスト ランに結果を追加するには、ケース ID を使用してテスト ケースと結果をマッピングします。実際の結果のほかに、サンプルのボディ コンテンツにあるように、簡単なコメントを追加できます。結果を追加するには、次のエンドポイントを使用します。

    1. カスタム結果フィールドが設定されている場合、下のサンプルの custom_failure_severity のように、custom_field_name というパターンを使用して値をサブミットできます。
    2. ステータス ID および詳細を確認するには、次のリクエストを実行します:
      GET  index.php?/api/v2/get_statuses
        • デフォルトのステータスは次のとおりです:
          • 1 – Passed
          • 2 – Blocked
          • 3 – Untested (デフォルト値であり、新たにステータスをサブミットする場合は使用できません)
          • 4 – Retest
          • 5 – Failed

    リクエスト

    POST  index.php?/api/v2/add_results_for_cases/{run_id}

    curl -X POST \ 
      -u "user@example.com:password" \ 
      -F "@path/to/data.json" \ 
      "https://example.testrail.io/index.php?/api/v2/add_results_for_cases/228"

    リクエスト ボディのサンプル

    {
        "results": [
            {
                "case_id": 4076,
                "status_id": 1,
                "comment": "This test passed",
                "elapsed": "5m",
                "environment": "qa03"
            },
            {
                "case_id": 4078,
                "status_id": 5,
                "comment": "This test failed",
                "assignedto_id": 5,
                "elapsed": "3m",
                "environment": "qa03",
                "defects": "TR-7",
                "custom_failure_severity": 3
            },
            {
                "case_id": 4079,
                "assignedto_id": 5,
                "comment": "No result, just a comment"
            }
        ]
    }

    レスポンス ボディのサンプル

    [
        {
            "id": 8658,
            "test_id": 18577,
            "status_id": 1,
            "created_on": 1684937736,
            "assignedto_id": null,
            "comment": "This test passed",
            "version": null,
            "elapsed": "5m",
            "defects": null,
            "created_by": 18,
            "custom_step_results": null,
            "custom_testrail_bdd_scenario_results": null,
            "custom_failure_severity": null,
            "attachment_ids": []
        },
        {
            "id": 8659,
            "test_id": 18578,
            "status_id": 5,
            "created_on": 1684937736,
            "assignedto_id": 5,
            "comment": "This test failed",
            "version": null,
            "elapsed": "3m",
            "defects": "TR-7",
            "created_by": 18,
            "custom_step_results": null,
            "custom_testrail_bdd_scenario_results": null,
            "custom_failure_severity": 3,
            "attachment_ids": []
        },
        {
            "id": 8660,
            "test_id": 18579,
            "status_id": null,
            "created_on": 1684937736,
            "assignedto_id": 5,
            "comment": "No result, just a comment",
            "version": null,
            "elapsed": null,
            "defects": null,
            "created_by": 18,
            "custom_step_results": null,
            "custom_testrail_bdd_scenario_results": null,
            "custom_failure_severity": null,
            "attachment_ids": []
        }
    ]

    個別のテスト手順を含む結果の追加

    個別のテスト手順は、より詳細にテスト結果を管理するための強力なメカニズムです。全体的なテスト結果を設定するだけでなく、各手順にテスト結果を設定し、手順が失敗した場合には、実際の動作をサブミットすることができます。手順の結果をサブミットするには、次のようなボディ コンテンツを使用します。

    リクエスト

    POST  index.php?/api/v2/add_results_for_cases/{run_id}

    curl -X POST \ 
      -u "user@example.com:password" \ 
      -F "@path/to/data.json" \ 
      "https://example.testrail.io/index.php?/api/v2/add_results_for_cases/228"

    リクエスト ボディのサンプル

    {
        "results": [
            {
                "case_id": 4078,
                "status_id": 5,
                "comment": "This test failed. See steps results below.",
                "elapsed": "3m",
                "environment": "qa03",
                "custom_step_results": [
                    {
                        "content": "Step 1",
                        "expected": "Expected Result 1",
                        "status_id": 1
                    },
                    {
                        "content": "Step 2",
                        "expected": "Expected Result 2",
                        "actual": "Actual Result 2",
                        "status_id": 5
                    }
                ]
            }
        ]
    }

    レスポンス ボディのサンプル

    [
        {
            "id": 8661,
            "test_id": 18578,
            "status_id": 5,
            "created_on": 1684938025,
            "assignedto_id": null,
            "comment": "This test failed. See steps results below.",
            "version": null,
            "elapsed": "3m",
            "defects": null,
            "created_by": 18,
            "custom_step_results": [
                {
                    "content": "Step 1",
                    "expected": "Expected Result 1",
                    "actual": "",
                    "additional_info": "",
                    "refs": "",
                    "status_id": "1"
                },
                {
                    "content": "Step 2",
                    "expected": "Expected Result 2",
                    "actual": "Actual Result 2",
                    "additional_info": "",
                    "refs": "",
                    "status_id": "5"
                }
            ],
            "custom_testrail_bdd_scenario_results": null,
            "custom_failure_severity": null,
            "attachment_ids": []
        }
    ]

    添付ファイルのインポート

    添付ファイルは、特にテストが失敗した場合に、テスト結果に追加のコンテキスト情報を提供するのに役立ちます。画面ショット、動画、実行ログなど、任意のタイプの添付ファイルを追加できます。

    最大許容アップロード サイズは 256MB に設定されていることに注意してください。

    リクエスト

    POST  index.php?/api/v2/add_attachment_to_result/{result_id}

    Content-Type: multipart/form-data
    curl -X POST \ 
      -u "user@example.com:password" \ 
      -H "Content-Type: multipart/form-data" \
      -F "attachment=@C:\\image.jpg" \ 
      "https://example.testrail.io/index.php?/api/v2/add_attachment_to_result/8661"

    リクエスト ボディのサンプル

    任意のファイル

    レスポンス ボディのサンプル

    { "attachment_id": "758c9b26-6038-4147-9a4d-74cd7af1499a" }

    テスト ランのクローズ

    インポートしたテスト ランおよびテスト結果を誰にも変更されたくない場合、次のエンドポイントを使用してテスト ランをクローズできます。

    リクエスト

    POST  index.php?/api/v2/close_run/{run_id}

    curl -X POST \ 
      -u "user@example.com:password" \ 
      -H "Content-Type: application/json" \
      "https://example.testrail.io/index.php?/api/v2/close_run/228"

    リクエスト ボディのサンプル

    なし

    レスポンス ボディのサンプル

    {
        "id": 228,
        "suite_id": 53,
        "name": "New test run",
        "description": "Test run description",
        "milestone_id": null,
        "assignedto_id": 5,
        "include_all": false,
        "is_completed": true,
        "completed_on": 1684939401,
        "config": null,
        "config_ids": [],
        "passed_count": 0,
        "blocked_count": 0,
        "untested_count": 1,
        "retest_count": 0,
        "failed_count": 2,
        "custom_status1_count": 0,
        "custom_status2_count": 0,
        "custom_status3_count": 0,
        "custom_status4_count": 0,
        "custom_status5_count": 0,
        "custom_status6_count": 0,
        "custom_status7_count": 0,
        "project_id": 27,
        "plan_id": null,
        "created_on": 1684936873,
        "updated_on": 1684936873,
        "refs": null,
        "dataset_id": null,
        "created_by": 18,
        "url": "https://marketing80testing.testrail-staging.com/index.php?/runs/view/228"
    }