none
REST API - HttpRequest - Test Plan, Test Suite and Test Case RRS feed

  • Question

  • I was able to create a test plan and test suite using the REST API as below.

    However I wasn't able to link the test suite back to the test plan...

    I noticed that the REST API documentation @ https://www.visualstudio.com/en-us/docs/integrate/api/test/suites#create-a-test-suite provides a different way of creating the Suite, however I can't get that to work - I keep getting the following error:

    {"$id":"1","innerException":null,"message":"TF400898: An Internal Error Occurred. Activity Id: 4c6aa504-24a1-48e0-8991-6c6bbb1467f8.","typeName":"System.Web.Http.HttpResponseException, System.Web.Http, Version=14.0.0.0,Culture=neutral, PublicKeyToken=xxxxxxxxxxx","typeKey":"HttpResponseException","errorCode":0,"eventId":0}

    Does anyone know how to create a test suite linked to the test plan?

    I suppose I will run into the same issue when creating the test cases as well...

    static void CreateTestPlan(HttpClient client, string project)
    {

    //JsonPatchDocument patchDocument = new JsonPatchDocument();
    Object[] patchDocument = new  Object [6];

    patchDocument[ 0 ] = new {op = "Add" , path = "/fields/System.WorkItemType" , value = "Test Plan" };
    patchDocument[ 1 ] = new {op = "Add" , path = "/fields/System.AreaPath" , value = "Test1" };
    patchDocument[ 2 ] = new {op = "Add" , path = "/fields/System.TeamProject" , value = "Test1" };
    patchDocument[ 3 ] = new {op = "Add" , path = "/fields/System.IterationPath" , value = "Test1" };
    patchDocument[ 4 ] = new {op = "Add" , path = "/fields/System.State" , value = "Active" };
    patchDocument[ 5 ] = new {op = "Add" , path = "/fields/System.Title" , value = "Test1 Plan" };
                
                //serialize the fields array into a json string
                var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json");

                var method = new HttpMethod("PATCH");
                var request = new HttpRequestMessage(method, "https://myServer.visualstudio.com/myProject/_apis/wit/workitems/$Test%20Plan?api-version=1.0") { Content = patchValue };
                var response = client.SendAsync(request).Result;

                //if the response is successfull, set the result to the workitem object
                    if (response.IsSuccessStatusCode)
                    {
                        //var workItem = response.Content.ReadAsAsync<WorkItem>().Result;
    Console.WriteLine("Success");
                        Console.WriteLine(response.Content.ReadAsStringAsync().Result);
                    }
                    else
                    {
    Console.WriteLine("FAILURE");
                        Console.WriteLine("Error creating bug: {0}", response.Content.ReadAsStringAsync().Result);
                    }


    }


    Tuesday, April 10, 2018 1:02 PM

All replies

  • Hi,

    Welcome to MSDN forum.

    It is recommend to go to Stackoverflow to discuss REST API. If you have problem about Microsoft Test manager, please feel free to let me know.

    Best regards,

    Joyce


    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, April 11, 2018 8:02 AM