如何将SoapUI的结果添加到Jira?

时间:2017-01-05 14:07:07

标签: groovy automated-tests jira soapui

我在SoapUI中自动化一些测试用例,我必须在Jira中添加自动化测试的结果。我怎么能这样做?
将在Jira中创建一个测试用例,我需要将该特定测试用例映射到我在SoapUI中自动化的测试用例,并在测试执行后添加结果。我只需要在Jira中看到结果通过/失败测试用例。
谢谢

1 个答案:

答案 0 :(得分:0)

以下是我在这种情况下会想到的方法。

我们假设soapui project中有一个测试套件。

Jira Issue Id应作为自定义属性添加到每个测试用例中,例如JIRA_ID

可以使用以下TearDown Script测试套件访问测试用例结果。 Below script只记录详细信息。

for ( testCaseResult in runner.results )
{
   testCaseName = testCaseResult.getTestCase().name
   log.info testCaseName
   if ( testCaseResult.getStatus().toString() == 'FAILED' )
   {
      log.info "$testCaseName has failed"
      for ( testStepResult in testCaseResult.getResults() )
      {
         testStepResult.messages.each() { msg -> log.info msg }
      }
   }
}

但是,在您的情况下,应分别为每个测试用例的jira issue id添加注释 为了实现这一点,不是一个简单的方法。使用以下任一方式:

  1. 编写一些代码(使用您的首选语言)来调用JIRA REST API来为问题添加评论。 wslite是我更喜欢的非常好的简单库。

  2. 使用soapui测试用例:

    • 添加一个rest方法,以便能够在jira中对项目进行评论。或者在一个单独的项目中,因为它与实际测试无关。见here
    • 创建一个虚拟测试用例,并使用此方法添加测试步骤。此测试用例可以在同一测试套件中或项目中的其他位置。
    • do not forget禁用此测试用例,因为这不是您的实际功能测试用例。
    • 只需更新消息&运行此禁用的测试步骤以在jira
    • 中更新
  3. 以下是稍加修改的测试套件TearDown Script,以满足您的要求。但是,您需要使用上述方法之一实现callJiraRestAPI方法。

    for ( testCaseResult in runner.results ) {
       testCaseName = testCaseResult.getTestCase().name
       def jiraId = testCaseResult.getTestCase().getPropertyValue('JIRA_ID')
       log.info testCaseName
       def message = new StringBuffer()
       if ( testCaseResult.getStatus().toString() == 'FAILED' ) {
          log.info "$testCaseName has failed"
          message.append("$testCaseName has failed")
          for ( testStepResult in testCaseResult.getResults() ) {
             testStepResult.messages.each() { msg -> 
                log.info msg
                message.append(msg) 
             }
          }
       } else {
         log.info "$testCaseName has passed"
         message.append("$testCaseName has passed")
       }
       //calling jira rest api to add the comment
       callJiraRestAPI(jiraId, testCaseResult.getTestCase(), message.toString())
    }
    
    
    //You need to Implement calling jira rest api to add the comment
    def callJiraRestAPI(jiraId, testKase, message) {
    //write your code using either 1 or 2 way
    //of course, REST request needs to be set with message
    //and jiraId is needed and testKase is useful if you choose to use 2nd way, otherwise not needed.
    }