I've tried with program below but test results are not added in VSTS:
public static void addTestResults() throws ClientProtocolException, IOException {
String pat = "abc@abc.com: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();
}
}
Following is the output:
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
}
Can anyone help me out where I am going wrong. I am trying to solve it for days but in vain.
I got the solution and here it is:
public static void addTestResults() throws ClientProtocolException, IOException {
String pat = "abc@abc.com: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();
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.