Help Center> CodeArts TestPlan> API Reference> Application Examples> Example 3: User Plan Operations
Updated on 2023-06-26 GMT+08:00

Example 3: User Plan Operations

Scenario

This scenario is applicable to those who have created projects in CodeArts TestPlan and have created cases in their own projects. You can create different plans to manage their own cases.

The following procedure describes how to create a test plan and add cases to the plan.

Prerequisites

You have created a project and created your own cases.

Involved APIs

User plan operations include creating a plan under a project and adding test cases to a plan in batches. To add test cases to a plan, you must have created test cases in advance. The following APIs are involved:

  • Creating a Plan in a Project: You can create your own test plan under the third-party test type in the project.
  • Adding Test Cases in Batches to a Plan: After the plan is created, associate test cases with the plan.

Procedure

  1. Determine the user token that can be used to authenticate the calling of other APIs.

    1. View the user token. For details, see Obtaining a User Token.
    2. Obtain the value of X-Subject-Token in the response header.

  2. Create a test plan.

    • API information

      URL format: POST /v1/projects/{project_id}/plans

      For details about API request parameters, see Creating a Plan in a Project.

    • Example request

      POST https://{endpoint}/v1/projects/{project_id}/plans

      • Obtain the value of {endpoint} from Endpoints.
      • {project_id} uniquely identifies a project.

      Body:

      {
        "name" : "is a test plan name.",
        "assigned_id" : "efdb403066474ab08836b9eeaaa23bca",
        "service_id_list" : [ 0 ],
        "plan_cycle" : {
          "start_date" : "2020-03-04",
          "end_date" : "2020-03-31"
        }
      }
    • Example response
      {
        "plan_id" : "efdb403066474ab08836b9eeaaa23bca",
        "error_code" : "CLOUDTEST.000XXXXXX",
        "error_msg" : "Failure cause: xxx"
      }

  3. Add a case to the test plan.

    • API information

      URL format: POST /v1/projects/{project_id}/plans/{plan_id}/testcases/batch-add

      For details about API request parameters, see Adding Test Cases in Batches to a Plan.

    • Example request

      POST https://{endpoint}/v1/projects/{project_id}/plans/{plan_id}/testcases/batch-add

      • Obtain the value of {endpoint} from Endpoints.
      • {project_id} uniquely identifies a project.

      Body:

      {
        "service_id" : 13,
        "testcase_id_list" : [ "efdb403066474ab08836b9eeaaa23bca", "251fca07b22f493692eb06b1754f07a8" ]
      }
    • Example response
      {
        "error_code" : "CLOUDTEST.000XXXXXX",
        "error_msg" : "Failure cause: xxx",
        "error_detail" : {
          "failed" : [ {
            "error_code" : "CLOUDTEST.000XXXXXX",
            "error_msg" : "Failure cause: xxx",
            "testcase_id" : "efdb403066474ab08836b9eeaaa23bca"
          } , {
            "error_code" : "CLOUDTEST.000XXXXXX",
            "error_msg" : "Failure cause: xxx",
            "testcase_id" : "251fca07b22f493692eb06b1754f07a8"
          }]
        }
      }