You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将JUnit/Cypress测试报告关联至Xray Jira指定测试用例?

解决方案

1. JUnit报告集成至Xray Jira(基于Jira工单编号)

  • 在JUnit测试中关联Jira工单:
    • 可在测试类/方法上通过@DisplayName标注Jira工单编号,比如@DisplayName("TEST-456: 用户登录功能测试");也可自定义注解,配合报告插件将工单编号写入JUnit报告的<properties>节点。
  • 使用Xray CLI工具导入报告:
    执行命令时指定目标测试执行的Jira工单key:
    xray import junit --file target/surefire-reports/TEST-*.xml --test-execution-key TEST-123
    
  • 构建工具集成(以Maven为例):
    配置maven-surefire-plugin生成含Jira信息的JUnit报告,再通过Xray Maven插件关联指定工单:
    <plugin>
      <groupId>com.xpandit.plugins</groupId>
      <artifactId>xray-maven-plugin</artifactId>
      <version>4.0.0</version>
      <executions>
        <execution>
          <goals>
            <goal>import-junit</goal>
          </goals>
          <configuration>
            <testExecutionKey>TEST-123</testExecutionKey>
            <junitReportPath>target/surefire-reports/</junitReportPath>
          </configuration>
        </execution>
      </executions>
    </plugin>
    

2. Cypress自定义XML报告关联已有Xray测试用例

要避免导入时生成新issuekey,核心是让XML报告中的每个测试用例携带已存在的Xray测试用例key,Xray会自动匹配关联:

  • 自定义Cypress报告结构:
    修改报告模板(或通过自定义脚本处理),在每个<testcase>节点下添加<properties>节点,指定对应测试用例的Xray key:
    <testcase name="用户登录成功测试" classname="login.spec.js">
      <properties>
        <property name="testkey" value="TEST-789"/>
      </properties>
      <!-- 测试结果信息 -->
    </testcase>
    
  • 借助Cypress报告插件实现:
    若使用cypress-xray-plugin,可在cypress.config.js中配置测试用例与Xray key的映射:
    const { defineConfig } = require('cypress');
    const xrayPlugin = require('cypress-xray-plugin');
    
    module.exports = defineConfig({
      e2e: {
        setupNodeEvents(on, config) {
          xrayPlugin(on, config, {
            testKey: {
              '用户登录成功测试': 'TEST-789',
              '用户密码错误测试': 'TEST-987'
            }
          });
          return config;
        },
      },
    });
    
  • 导入时的注意事项:
    使用Xray API或CLI导入时,确保指定测试执行工单key,且报告中所有testkey对应的用例已在Jira中存在。若合并报告存在遗漏testkey的测试条目,Xray会自动创建新issuekey,需检查报告生成逻辑补全所有映射。

内容的提问来源于stack exchange,提问作者Seid Hassen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.11 04:30:50