RESTのAPIのJavaを通じてAzureのDevOpsチームでのテスト結果を追加する方法?

羊 :

私は、以下のプログラムを試してみたが、テストの結果は、VSTSで追加されていません。

public static void addTestResults() throws ClientProtocolException, IOException {
     String pat = "[email protected]:xxxxxxxxxxxxxxxxxxxxxx";
     byte[] byteArray2 = Base64.encodeBase64(pat.getBytes());
     String encodedString2 = new String(byteArray2);

     HttpClient httpClient = HttpClientBuilder.create().build();
     HttpPost postRequest = new HttpPost("https://xxx.visualstudio.com/DefaultCollection/XXX/_apis/test/runs/1000012/results?api-version=5.0-preview.5" );
     List<NameValuePair> arguments1 = new ArrayList<NameValuePair>(4);
     arguments1.add(new BasicNameValuePair("state", "Completed"));
     arguments1.add(new BasicNameValuePair("testPoint", "{\"id\":40}"));
     arguments1.add(new BasicNameValuePair("outcome", "Passed"));
     arguments1.add(new BasicNameValuePair("testCase", "{\"id\":7340}"));

     try {
         postRequest.setHeader(HttpHeaders.CONTENT_TYPE, "application/json");
         patchRequest.setHeader(HttpHeaders.ACCEPT, "application/json");
         postRequest.setHeader("Authorization", "Basic "+encodedString2);
         postRequest.setEntity(new UrlEncodedFormEntity(arguments1,"UTF-8"));

         HttpResponse response = httpClient.execute(postRequest);
         System.out.println("Out is"+EntityUtils.toString(response.getEntity()));

     }    catch (IOException e) {
         e.printStackTrace();
     }
}

以下が出力されます。

Out is
{  
"$id":"1",
"innerException":null,
"message":"Value cannot be null.\r\nParameter name: results",
"typeName":"System.ArgumentNullException, mscorlib",
"typeKey":"ArgumentNullException",
"errorCode":0,
"eventId":0
}

私が間違っているつもり缶誰の助け私アウト。私は日のためではなく、無駄にそれを解決しようとしています。

羊 :

私は解決策を持って、ここにあります:

public static void addTestResults() throws ClientProtocolException, IOException {
     String pat = "[email protected]:xxxxxxxxxxxxxxxxxxxxxx";
     byte[] byteArray2 = Base64.encodeBase64(pat.getBytes());
     String encodedString2 = new String(byteArray2);
    String reqbody = "{\n" + 
            "        \"state\": \"Completed\",\n" + 
            "        \"testPoint\": {\n" + 
            "          \"id\": 40\n" + 
            "        },\n" + 
            "        \"outcome\": \"Passed\",\n" + 
            "        \"testCase\": {\n" + 
            "          \"id\": 7390\n" + 
            "        }\n" + 
            "      }";
     HttpClient httpClient = HttpClientBuilder.create().build();
     HttpPost postRequest = new HttpPost("https://xxx.visualstudio.com/DefaultCollection/XXX/_apis/test/runs/1000012/results?api-version=5.0-preview.5" );


     try {
         postRequest.setHeader(HttpHeaders.CONTENT_TYPE, "application/json");
         patchRequest.setHeader(HttpHeaders.ACCEPT, "application/json");
         postRequest.setHeader("Authorization", "Basic "+encodedString2);
         postRequest.setEntity(new StringEntity(reqbody, ContentType.APPLICATION_JSON));

         HttpResponse response = httpClient.execute(postRequest);
         System.out.println("Out is"+EntityUtils.toString(response.getEntity()));

     }    catch (IOException e) {
         e.printStackTrace();
     }
}

おすすめ

転載: http://43.154.161.224:23101/article/api/json?id=195303&siteId=1