问题
I have figured out how to add an attachment to TestCase, Defect objects, but I can't, using the same mechanism, seem to attach a test result file to a TestCaseResult object. I am getting an error message of "validation error: Attachment.attachments[0] should not be null". I've tried attaching during the creation of the test result as well as updating an existing, previously created, test result. I would be surprised if attaching a test result file to a TestCaseResult is not supported as this is common mainstream behavior. Thanks.
My code:
private Attachment createAttachment(string resultsFile) { byte[] bytes = readFileAsByteArray(resultsFile);
// Create attachment content;
AttachmentContent attachmentContent = new AttachmentContent();
attachmentContent.Content = bytes;
attachmentContent.Workspace = this.m_targetWorkspace;
CreateResult result = m_rallyService.create(attachmentContent);
attachmentContent = (AttachmentContent)result.Object;
//attachmentContent = (AttachmentContent)this.m_rallyService.read(attachmentContent, this.m_targetWorkspace);
Attachment attachment = new Attachment();
attachment.ContentType = "application / vnd.openxmlformats - officedocument.wordprocessingml.document";
attachment.Content = attachmentContent;
attachment.Name = "Bubba.docx";
attachment.Size = bytes.Length;
attachment.SizeSpecified = true;
attachment.User = this.m_rallyUser;
//attachment.Artifact = testResult;
attachment.Workspace = this.m_targetWorkspace;
result = m_rallyService.create(attachment);
attachment = (Attachment)result.Object;
//attachment = (Attachment)this.m_rallyService.read(attachment, this.m_targetWorkspace);
return attachment;
}
回答1:
In deed it now works. The Attachment object now has an attribute TestCaseResult which when set, attaches the attachment to the created result. My revised code:
private Attachment createAttachment(TestCaseResult testCaseResult, string resultsFile)
{
byte[] bytes = readFileAsByteArray(resultsFile);
// Create attachment content;
AttachmentContent attachmentContent = new AttachmentContent();
attachmentContent.Content = bytes;
attachmentContent.Workspace = this.m_targetWorkspace;
CreateResult result = m_rallyService.create(attachmentContent);
attachmentContent = (AttachmentContent)result.Object;
// Create attachment.
Attachment attachment = new Attachment();
// Microsoft Word document.
attachment.ContentType = "application / vnd.openxmlformats - officedocument.wordprocessingml.document";
attachment.Content = attachmentContent;
// Parse out file name.
string[] parts = resultsFile.Split(new char[] { '\\' });
attachment.Name = parts[parts.Length - 1];
attachment.Size = bytes.Length;
attachment.SizeSpecified = true;
attachment.User = this.m_rallyUser;
attachment.TestCaseResult = testCaseResult;
attachment.Workspace = this.m_targetWorkspace;
result = m_rallyService.create(attachment);
attachment = (Attachment)result.Object;
return attachment;
}
回答2:
Unfortunately you've encountered a known Defect with the Rally Webservices API. Rally Product Development is working on a fix - I'd recommend filing a case with Rally Support (rallysupport@rallydev.com) nonetheless, as this will associate your inquiry to the Defect and you'll be notified when it has been fixed.
回答3:
As of the 5/26/2012 Rally code release, this Defect has been fixed.
回答4:
If attachment belongs to the test_case_result it should use attachment.artifact:
Artifact
Required false
Note The artifact this attachment belongs to.
One-To-One Relationship Artifact
Why do we need Attachment.TestCaseResult instead of simple Attachment.Artifact ?
TestCaseResult
Required false
Note Associated Test Case Result
One-To-One Relationship TestCaseResult
来源:https://stackoverflow.com/questions/10372917/rally-soap-api-how-do-i-add-an-attachment-to-a-testcaseresult