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

求助:如何为Webdriver IO的JUnit XML添加Xray测试用例自定义属性test key

给JUnit XML添加Test Key以导入Xray平台

直接在<testcase>元素添加testKey属性

JUnit XML的<testcase>标签支持自定义属性,你可以直接把Xray的test key(比如TEST-123)作为属性写入,Xray导入时会自动识别并关联对应测试用例。示例代码:

<testsuite name="MyTestSuite" tests="1" skipped="0" failures="0" errors="0" timestamp="2024-05-20T10:00:00" hostname="localhost">
  <testcase name="LoginTest" classname="com.example.LoginTest" time="0.5" testKey="TEST-123">
    <!-- 测试结果细节(如failure/error标签) -->
  </testcase>
</testsuite>

通过<properties>子元素定义testKey

如果你的测试框架不支持直接给testcase加自定义属性,可以在<testcase>下嵌套<properties>节点,用<property>指定testKey,同样能被Xray解析:

<testcase name="CheckoutTest" classname="com.example.CheckoutTest" time="1.2">
  <properties>
    <property name="testKey" value="TEST-456"/>
  </properties>
  <!-- 测试结果内容 -->
</testcase>

JUnit 5代码层面自动注入(可选)

如果是用JUnit 5写测试,能通过自定义注解+扩展实现自动生成带testKey的XML:

  1. 先定义一个注解:
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface XrayTestKey {
    String value();
}
  1. 给测试方法加注解:
@Test
@XrayTestKey("TEST-789")
void testPaymentFlow() {
    // 测试逻辑
}
  1. 编写JUnit 5扩展类(核心是在生成XML报告时,从注解中读取testKey并添加到<testcase>属性里,具体实现可结合框架的报告扩展点)

导入Xray的注意事项

  • 确保testKey和Xray中已存在的测试用例Key完全匹配(区分大小写)
  • 导入时在Xray界面选"JUnit XML"格式,系统会自动匹配testKey并更新对应用例的执行结果
  • 若匹配失败,先检查XML里的testKey拼写,再确认Xray中是否存在该测试用例

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.29 01:17:35