Rally SOAP API - 如何向 TestCaseResult 添加附件

本文关键字:TestCaseResult 添加 SOAP API Rally | 更新日期: 2023-09-27 18:32:48

我已经想出了如何将附件添加到TestCase,Defect对象,但是我不能使用相同的机制将测试结果文件附加到TestCaseResult对象。 我收到"验证错误:附件[0]不应为空"的错误消息。 我尝试在创建测试结果期间附加,以及更新以前创建的现有测试结果。 如果不支持将测试结果文件附加到 TestCaseResult 中,我会感到惊讶,因为这是常见的主流行为。 谢谢。

我的代码:

私有附件创建附件(字符串结果文件) { 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;
    }

Rally SOAP API - 如何向 TestCaseResult 添加附件

实际上,它现在可以工作了。 附件对象现在有一个属性 TestCaseResult 设置后,该属性会将附件附加到创建的结果。 我修改后的代码:

   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;
      }
不幸的是,

您在Rally Webservices API中遇到了一个已知的缺陷。Rally 产品开发部门正在修复 - 尽管如此,我还是建议向 Rally 支持 (rallysupport@rallydev.com) 提交案例,因为这会将您的查询与缺陷相关联,并且您会在修复后收到通知。

自 2012 年 5 月 26 日拉力赛代码发布起,此缺陷已得到修复。

如果附件属于test_case_result则应使用 attachment.artifact:

Artifact
Required    false
Note    The artifact this attachment belongs to.
One-To-One Relationship Artifact

为什么我们需要 Attachment.TestCaseResult 而不是简单的 Attachment.Artifact?

TestCaseResult    
Required    false
Note    Associated Test Case Result
One-To-One Relationship TestCaseResult