我使用Java的Rally REST API解决方案在一个工作区内正常运行。 当工作空间不同时,请告知插入测试用例结果。我被困在以下情况中,如下所述:*
设置
步骤
我正在尝试在工作区YYY中为测试用例TC1设置结果,但似乎没有更新并且失败并出现以下错误。
// Query for Test Case to which we want to add results
QueryRequest testCaseRequest = new QueryRequest("TestCase");
testCaseRequest.setFetch(new Fetch("FormattedID","Name"));
testCaseRequest.setQueryFilter(new QueryFilter("FormattedID", "=", testCaseId));
String workspaceRef = "/workspace/YYY";
String projectRef = "/project/QQQ";
testCaseRequest.setWorkspace(workspaceRef);
testCaseRequest.setProject(projectRef);
QueryResponse testCaseQueryResponse = restApi.query(testCaseRequest);
JsonObject testCaseJsonObject = testCaseQueryResponse.getResults().get(0).getAsJsonObject();
String testCaseRef = testCaseJsonObject.get("_ref").toString();
//Add a Test Case Result
System.out.println("Creating Test Case Result...");
JsonObject newTestCaseResult = new JsonObject();
newTestCaseResult.addProperty("Verdict", result);
java.util.Date date= new java.util.Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
String timestamp = sdf.format(date);
newTestCaseResult.addProperty("Date", timestamp);
newTestCaseResult.addProperty("Notes", "Automated Test Runs");
newTestCaseResult.addProperty("Build", build);
newTestCaseResult.addProperty("Tester", userRef);
newTestCaseResult.addProperty("TestCase", testCaseRef);
CreateRequest createRequest = new CreateRequest("testcaseresult", newTestCaseResult);
CreateResponse createResponse = restApi.create(createRequest);
此错误在最后一行失败:
"{"CreateResult": {"_rallyAPIMajor": "1", "_rallyAPIMinor": "37", "Errors": ["Could not set value for Test Case: Cannot connect object to value, Test Case value is in a different workspace. [object workspace OID=XXX, value workspace OID=YYY"], "Warnings": []}}"
答案 0 :(得分:1)
如果您没有指定创建TestCaseResult的工作空间,则默认为您的配置文件默认值(在这种情况下与相关的TestCase工作空间不同)。
如果在创建之前添加以下代码,则应该成功:
newTestCaseResult.addProperty("Workspace", testCaseJsonObject.get("Workspace").getAsJsonObject().get("_ref").getAsString());
您还需要在原始查询中获取Workspace:
testCaseRequest.setFetch(new Fetch("FormattedID","Name", "Workspace"));
您认为WSAPI应该能够从链接的TestCase推断出正确的工作空间,但这是所有对象类型创建的常见行为。