问题
I have created Rally utility that download userstory, create testcase, testplan, update test result. I got an enhancement request to create testset and update the test result to it. I am able to create testset and group test case into it but I am not able to update the test set with the test result. I am using below code to update test result for test set but getting error. Please help where I am wrong with the code.
Note: When I remove the line newTestCaseResult.addProperty("TestSet", testSetRef);
it updates test result separately but the results are not updated within test set.
Error Received:
Error occurred updating test result in rally
Invalid attempt to add attribute c_ExternalID with oid 256,641,060,196 from type TestCase with oid 51,486,618,775. Valid types for this list are: TestCase, ScheduledTestCase, ScheduledTestCase, RankableArtifact, PersistableObject, DomainObject, ScheduledTestCase, WorkspaceDomainObject, Artifact
QueryRequest testSetRequest = new QueryRequest("TestSet");
testSetRequest.setQueryFilter(new QueryFilter("FormattedID", "=", "TS20"));
QueryResponse testSetQueryResponse = restApi.query(testSetRequest);
if (testSetQueryResponse.wasSuccessful()) {
System.out.println("Successful: " + testSetQueryResponse.wasSuccessful());
System.out.println("Size: " + testSetQueryResponse.getTotalResultCount());
for (int i = 0; i < testSetQueryResponse.getResults().size(); i++) {
JsonObject testSetJsonObject = testSetQueryResponse.getResults().get(i).getAsJsonObject();
System.out.println("Name: " + testSetJsonObject.get("Name") + " ref: " + testSetJsonObject.get("_ref").getAsString() + " Test Cases: " + testSetJsonObject.get("TestCases").getAsJsonObject().get("_ref"));
int numberOfTestCases = testSetJsonObject.get("TestCases").getAsJsonObject().get("Count").getAsInt();
System.out.println(numberOfTestCases);
if (numberOfTestCases > 0) {
QueryRequest testCaseRequest = new QueryRequest(testSetJsonObject.getAsJsonObject("TestCases"));
testCaseRequest.setFetch(new Fetch("FormattedID"));
//load the collection
JsonArray testCases = restApi.query(testCaseRequest).getResults();
for (int j = 0; j < numberOfTestCases; j++) {
System.out.println(testCases.get(j).getAsJsonObject().get("FormattedID").getAsString());
String s = testCases.get(j).getAsJsonObject().get("FormattedID").getAsString();
testCaseRequest = new QueryRequest("TestCase");
testCaseRequest.setFetch(new Fetch("FormattedID", "Name"));
testCaseRequest.setQueryFilter(new QueryFilter("FormattedID", "=", s));
QueryResponse testCaseQueryResponse = restApi.query(testCaseRequest);
String testCaseRef =
testCaseQueryResponse.getResults().get(0).getAsJsonObject().get("_ref").getAsString();
java.util.Date date = new java.util.Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
String timestamp = sdf.format(date);
try {
//Add a Test Case Result
System.out.println("Creating Test Case Result...");
JsonObject newTestCaseResult = new JsonObject();
newTestCaseResult.addProperty("Verdict", "Pass");
newTestCaseResult.addProperty("Date", timestamp);
newTestCaseResult.addProperty("Notes", "Automated Selenium Test Runs");
newTestCaseResult.addProperty("Build", "Release 2");
newTestCaseResult.addProperty("TestCase", testCaseRef);
newTestCaseResult.addProperty("TestSet", testSetRef);
CreateRequest createRequest = new CreateRequest("testcaseresult", newTestCaseResult);
CreateResponse createResponse = restApi.create(createRequest);
if (createResponse.wasSuccessful()) {
System.out.println(String.format("Created %s", createResponse.getObject().get("_ref").getAsString()));
//Read Test Case
String ref = Ref.getRelativeRef(createResponse.getObject().get("_ref").getAsString());
System.out.println(String.format("\nReading Test Case Result %s...", ref));
GetRequest getRequest = new GetRequest(ref);
getRequest.setFetch(new Fetch("Date", "Verdict"));
GetResponse getResponse = restApi.get(getRequest);
JsonObject obj = getResponse.getObject();
System.out.println(String.format("Read Test Case Result. Date = %s, Verdict = %s", obj.get("Date").getAsString(), obj.get("Verdict").getAsString()));
} else {
String[] createErrors;
createErrors = createResponse.getErrors();
System.out.println("Error occurred creating Test Case: ");
for (i = 0; i < createErrors.length; i++) {
System.out.println(createErrors[i]);
}
}
} finally {
}
}
}
}
} else {
String[] createErrors;
createErrors = testSetQueryResponse.getErrors();
System.out.println("Error occurred creating Test Case: ");
for (int i = 0; i < createErrors.length; i++) {
System.out.println(createErrors[i]);
}
}
来源:https://stackoverflow.com/questions/62153903/update-rally-testset-with-test-results