【发布时间】:2019-01-02 10:38:20
【问题描述】:
我试过下面的程序,但测试结果没有添加到 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();
}
}
以下是输出:
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
}
谁能帮我找出哪里出错了。我试图解决它几天但徒劳无功。
【问题讨论】:
-
看来,您的 json 无效。您需要获取正确的请求示例并与您发送的最终请求正文进行比较。如果您可以在此处提供此示例,将更容易发现问题。
-
POST dev.azure.com/fabrikam/Fabrikam-Fiber-TFVC/_apis/test/Runs/24/… 请求正文:[ {“testCaseTitle”:“VerifyWebsiteTheme”,“automatedTestName”:“FabrikamFiber.WebSite.TestClass.VerifyWebsiteTheme”,“优先级”:1,“结果”:“通过“},{“testCaseTitle”:“VerifyWebsiteLinks”,“automatedTestName”:“FabrikamFiber.WebSite.TestClass.VerifyWebsiteLinks”,“优先级”:2,“结果”:“失败”,“关联错误”:[{“id” : 30 } ] } ]
-
在请求中发送的请求体呢?你能得到正在发送的最终请求吗?您可以使用调试来获取它。
标签: java selenium-webdriver azure-devops azure-devops-rest-api