关于 Testomat Allure Adapter Setup
为使用 Allure 的 Java 项目配置 Testomat.io 报告或规划迁移的技能。它提供适配器和注解迁移两种路径,并避免未经确认移除不支持的 Allure 用法。
主要功能
- 01选择适配器或迁移模式
- 02配置 Allure 适配器
- 03映射受支持的注解替换
- 04谨慎处理不受支持的注解
- 05检查 Maven Surefire javaagent 设置
适用场景
- 01为 Allure 项目添加 Testomat.io 报告
- 02规划 Allure 注解迁移
- 03检查注解替换与冲突
- 04配置 Maven Surefire javaagent
安装
复制下面的命令,在终端中运行。
npx skills add https:/ / github.com/ testomatio/ skills --skill testomat-allure-adapter-setup安装后在 Claude Code 中输入/testomat-allure-adapter-setup确认已加载。
详细介绍
Testomat Allure 适配器
为已使用 Allure 的 Java 项目配置 Testomat.io 报告。有两种模式:保留 Allure 并添加适配器,或迁移到原生 Testomat.io 注解。
配置项目之前,先询问用户希望使用哪种模式:
您想保留现有的 Allure 注解,仅使用 Testomat.io 报告测试结果,还是希望将 Allure 注解替换为 Testomat.io 注解?
选项 1:保留 Allure 并向 Testomat.io 报告
在以下情况下使用此选项:
- 项目已使用 Allure 注解。
- 用户希望保留
@Epic、@Feature、@Story、@Owner、@Severity等注解。
适配器只会将数据从 Allure 传输到 Testomat.io。它不会将注解从 Testomat.io 迁移、生成或同步回 Allure。
安装 Testomat Allure Adapter。
Maven
<dependency>
<groupId>io.testomat</groupId>
<artifactId>testomat-allure-adapter</artifactId>
<version><LATEST_STABLE_VERSION></version>
</dependency>
Gradle
implementation 'io.testomat:testomat-allure-adapter:<LATEST_STABLE_VERSION>'
选项 2:从 Allure 迁移到 Testomat.io
在以下情况下使用此选项:
- 用户希望停止使用 Allure 注解。
- 用户只希望使用 Testomat.io 注解和报告。
- 项目是新项目,或计划进行迁移。
将项目迁移到标准的 Testomat.io 报告器。
仅当以下两个条件均满足时,才移除 Allure 依赖:
- 用户明确选择移除不受支持的 Allure 注解。
- 项目中已不再包含任何 Allure 注解、API、监听器或报告集成。
支持的替换项
自动应用以下替换:
@DisplayName → @Title (automatic)
@AllureId → @TestId (automatic)
@TmsLink → @TestId (automatic)
@Attachment → @Artifact (automatic)
@Step → @Step (automatic)
不受支持的 Allure 注解
其他所有 Allure 注解(@Epic、@Feature、@Story、@Owner、@Severity、@Description、@Issue 等)都没有对应的 Testomat.io 注解。绝不自动迁移、替换或移除这些注解。
如果检测到任何此类注解,请询问:
检测到不受支持的 Allure 注解。Testomat.io 目前未为这些注解提供直接替代项。您想保留还是移除它们?
如果用户选择保留:
- 保留这些注解、Allure 依赖和 Allure 配置。
如果用户选择移除:
- 移除不受支持的注解。
- 仅使用受支持的 Testomat.io 注解继续迁移。
- 仅在满足上述条件时移除 Allure 依赖。
替换 @DisplayName
@DisplayName("Login test")
↓
@Title("Login test")
import org.junit.jupiter.api.DisplayName;
↓
import io.testomat.core.annotation.Title;
替换 @AllureId
@AllureId("a1b2c3d4")
↓
@TestId("a1b2c3d4")
import io.qameta.allure.AllureId;
↓
import io.testomat.core.annotation.TestId;
替换 @TmsLink
@TmsLink("k8m2x9q1")
↓
@TestId("k8m2x9q1")
import io.qameta.allure.TmsLink;
↓
import io.testomat.core.annotation.TestId;
@AllureId 与 @TmsLink 冲突
如果同一个测试上同时存在两者:
- 不要自动替换。
- 两者都映射到
@TestId,而 Testomat.io 每个测试只支持一个@TestId。 - 询问用户要使用哪个值。
替换 @Step
import io.qameta.allure.Step;
↓
import io.testomat.core.annotation.Step;
@io.qameta.allure.Step
↓
@io.testomat.core.annotation.Step
替换 @Attachment
import io.qameta.allure.Attachment;
↓
import io.testomat.core.annotation.Artifact;
@Attachment
↓
@Artifact
替换 Allure.step
在替换任何内容之前,先分析检测到的所有 Allure.step(...) 重载。
支持的替换:
Allure.step(String name)
↓
Testomatio.step(String name, () -> {})
Allure.step(String name, Status status)
↓
Testomatio.step(String name, () -> {})
Status 值会被丢弃:Testomatio.step(...) 不支持覆盖步骤状态。
Allure.step(ThrowableContextRunnableVoid<StepContext> runnable)
↓
Testomatio.step("", () -> { /* original runnable body */ })
Allure.step(String name, ThrowableContextRunnableVoid<StepContext> runnable)
↓
Testomatio.step(String name, () -> { /* original runnable body */ })
Allure.step(String name, ThrowableRunnableVoid runnable)
↓
Testomatio.step(String name, () -> { /* original runnable body */ })
规则:
- 尽可能保留原始步骤名称。
- 将原始可运行代码体移入
Testomatio.step(...)的Runnable参数。
不支持返回值的重载,因为 Testomatio.step(String stepDescription, Runnable function) 不会返回值:
Allure.step(String name, ThrowableRunnable<T> runnable)
Allure.step(ThrowableContextRunnable<T, StepContext> runnable)
Allure.step(String name, ThrowableContextRunnable<T, StepContext> runnable)
如果检测到返回值重载,请询问:
某些 Allure.step(...) 用法会返回值,无法自动迁移,因为 Testomatio.step(...) 不支持返回值。你希望如何继续?
选项:
- 替换受支持的重载,并保持不受支持的重载不变。
- 完全跳过 Allure.step 迁移,并保留所有现有用法。
如果用户选择选项 1:
- 替换受支持的重载。
- 保持返回值重载不变。
- 告知用户哪些用法需要手动迁移。
如果用户选择选项 2:
- 保持所有
Allure.step(...)用法不变。
只要项目中仍有任何 Allure.step(...) 用法,就保留 Allure 依赖。
替换 Allure.addAttachment
- 在步骤内,替换为
Testomatio.stepArtifact(String pathToFile)。 - 在步骤外,替换为
Testomatio.artifact(String pathToFile)。
必需的 Maven Surefire Plugin 配置
始终检查 Maven Surefire Plugin 配置。如果项目使用了它:
- 如果未配置
argLine,使用项目依赖中声明的版本添加 AspectJ javaagent。 - 如果已存在
argLine,保留其现有值并附加 javaagent。请勿覆盖或移除现有 JVM 参数。 - 如果无法确定 AspectJ 版本,在添加 javaagent 前询问用户。
<argLine>
-javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
</argLine>