# TMS 链接注解

> For the complete documentation index, see [llms.txt](https://www.jetbrains.com.cn/help/idea/llms.txt).

注解是代码中的特殊标记，包含有关代码的元数据。 您可以使用 TMS 链接注释来提供有关测试的更多信息。 这样可以使 IntelliJ IDEA 将您的单元测试链接到 TMS 项。

TMS 链接注释使 IntelliJ IDEA 能够进行更好的分析，例如，查找已经从单元测试中引用的测试用例。

> **Tip:**
> 一个注解只是一个类，其声明类似于以下内容：
>
>
>
>
> ```
> @interface MyAnnotation { } // Java
> annotation class MyAnnotation // Kotlin
>
> ```

您的项目可能已经使用了将代码链接到相应测试的注释。 如果是这样，您可以继续 [配置 IntelliJ IDEA 以识别此注解。](#configure-settings)

如果没有，您可以 [使用第三方注解](#use-third-party-annotation)或 [创建您自己的自定义注解](#create-custom-annotation)。 两种选项都同样有效。

Maven:

Procedure: 导入第三方注解

1. 在项目根目录中打开  `pom.xml` 。

> **Tip:**
> 若要快速定位到某个文件，请按 `Ctrl+Shift+N` (Windows), `⌘ ⇧ O` (macOS), `⌘ ⇧ N` (IntelliJ IDEA Classic (macOS)), `⌘ ⇧ O` (macOS System Shortcuts), `Ctrl+Shift+N` (XWin), `Ctrl+Shift+N` (GNOME), `Ctrl+Shift+N` (KDE), `Ctrl+X, Ctrl+F` (Emacs), `Ctrl+P` (Sublime Text), `⌘ P` (Sublime Text (macOS)), `Ctrl+Shift+T` (Visual Studio), `⌘ ⇧ T` (Visual Studio (macOS)), `Alt+Shift+O` (NetBeans), `Ctrl+Shift+R` (Eclipse), `⌘ ⇧ R` (Eclipse (macOS)) 并输入其名称。

2. 在  `pom.xml`  中，按 `Alt+Insert` (Windows), `⌘ N` (macOS), `⌃ N` (IntelliJ IDEA Classic (macOS)), `⌘ N` (macOS System Shortcuts), `Alt+Insert` (XWin), `Alt+Insert` (GNOME), `Alt+Insert` (KDE), `Alt+Insert` (Emacs), `Alt+Insert` (Sublime Text), `⌘ N` (Sublime Text (macOS)), `Alt+Insert` (Visual Studio), `⌘ ⌃ N` (Visual Studio (macOS)), `Alt+Insert` (NetBeans), `Alt+Insert` (Eclipse), `⌘ N` (Eclipse (macOS))，然后选择   依赖  。

![生成依赖项](https://resources.jetbrains.com.cn/help/img/idea/2026.3/aqua_tms_generate_annotation_maven.png)

3. 在打开的工具窗口中，输入依赖项的名称，例如，  `io.qameta.allure:allure-java-commons` 。

请确保选择所需的依赖项版本，然后点击   添加  。

![选择依赖项](https://resources.jetbrains.com.cn/help/img/idea/2026.3/aqua_tms_import_annotation.png)

4. 在构建脚本中应用更改。 为此，请按 `Ctrl+Shift+O` (Windows), `Ctrl+Shift+O` (macOS), `Ctrl+Shift+O` (IntelliJ IDEA Classic (macOS)), `Ctrl+Shift+O` (macOS System Shortcuts), `Ctrl+Shift+O` (XWin), `Ctrl+Shift+O` (GNOME), `Ctrl+Shift+O` (KDE), `Ctrl+Shift+O` (Emacs), `Ctrl+Shift+O` (Sublime Text), `Ctrl+Shift+O` (Sublime Text (macOS)), `Ctrl+Shift+O` (Visual Studio), `Ctrl+Shift+O` (Visual Studio (macOS)), `Ctrl+Shift+O` (NetBeans), `Ctrl+Shift+O` (Eclipse), `Ctrl+Shift+O` (Eclipse (macOS))，或在编辑器右上角出现的通知中点击   同步 Maven 更改  。

![正在加载更改](https://resources.jetbrains.com.cn/help/img/idea/2026.3/aqua_tms_import_annotation_reload_maven.png)

Gradle:

Procedure: 导入第三方注解

1. 在项目根目录中打开  `build.gradle` 。

> **Tip:**
> 若要快速定位到某个文件，请按 `Ctrl+Shift+N` (Windows), `⌘ ⇧ O` (macOS), `⌘ ⇧ N` (IntelliJ IDEA Classic (macOS)), `⌘ ⇧ O` (macOS System Shortcuts), `Ctrl+Shift+N` (XWin), `Ctrl+Shift+N` (GNOME), `Ctrl+Shift+N` (KDE), `Ctrl+X, Ctrl+F` (Emacs), `Ctrl+P` (Sublime Text), `⌘ P` (Sublime Text (macOS)), `Ctrl+Shift+T` (Visual Studio), `⌘ ⇧ T` (Visual Studio (macOS)), `Alt+Shift+O` (NetBeans), `Ctrl+Shift+R` (Eclipse), `⌘ ⇧ R` (Eclipse (macOS)) 并输入其名称。

2. 在  `build.gradle`  中，按 `Alt+Insert` (Windows), `⌘ N` (macOS), `⌃ N` (IntelliJ IDEA Classic (macOS)), `⌘ N` (macOS System Shortcuts), `Alt+Insert` (XWin), `Alt+Insert` (GNOME), `Alt+Insert` (KDE), `Alt+Insert` (Emacs), `Alt+Insert` (Sublime Text), `⌘ N` (Sublime Text (macOS)), `Alt+Insert` (Visual Studio), `⌘ ⌃ N` (Visual Studio (macOS)), `Alt+Insert` (NetBeans), `Alt+Insert` (Eclipse), `⌘ N` (Eclipse (macOS))，然后选择   添加 Maven 工件依赖  。

![生成依赖项](https://resources.jetbrains.com.cn/help/img/idea/2026.3/aqua_tms_generate_annotation_gradle.png)

3. 在打开的工具窗口中，输入依赖项的名称，例如，  `io.qameta.allure:allure-java-commons` 。

请确保选择所需的依赖项版本，然后点击   添加  。

![选择依赖项](https://resources.jetbrains.com.cn/help/img/idea/2026.3/aqua_tms_import_annotation.png)

4. 在构建脚本中应用更改。 为此，请按 `Ctrl+Shift+O` (Windows), `Ctrl+Shift+O` (macOS), `Ctrl+Shift+O` (IntelliJ IDEA Classic (macOS)), `Ctrl+Shift+O` (macOS System Shortcuts), `Ctrl+Shift+O` (XWin), `Ctrl+Shift+O` (GNOME), `Ctrl+Shift+O` (KDE), `Ctrl+Shift+O` (Emacs), `Ctrl+Shift+O` (Sublime Text), `Ctrl+Shift+O` (Sublime Text (macOS)), `Ctrl+Shift+O` (Visual Studio), `Ctrl+Shift+O` (Visual Studio (macOS)), `Ctrl+Shift+O` (NetBeans), `Ctrl+Shift+O` (Eclipse), `Ctrl+Shift+O` (Eclipse (macOS))，或在编辑器右上角出现的通知中点击   同步 Gradle 更改  。

![正在加载更改](https://resources.jetbrains.com.cn/help/img/idea/2026.3/aqua_tms_import_annotation_reload_gradle.png)

如果您不能为模块添加额外的依赖项，您可以创建自己的注解类。

Java:

Procedure: 创建自定义注解

1. 在   项目   工具窗口 ( `Alt+1` (Windows), `⌘ 1` (macOS), `⌘ 1` (IntelliJ IDEA Classic (macOS)), `⌘ 1` (macOS System Shortcuts), `Alt+1` (XWin), `Alt+1` (GNOME), `Alt+1` (KDE), `Alt+1` (Emacs), `Alt+1` (Sublime Text), `⌘ 1` (Sublime Text (macOS)), `Ctrl+Alt+L` (Visual Studio), `⌘ ⌥ L` (Visual Studio (macOS)), `Ctrl+1` (NetBeans), `Alt+1` (Eclipse), `Alt+1` (Eclipse (macOS))) 中，右键点击要在其中创建新类的节点，然后选择  `新建 | Java 类` 。

2. 将以下代码粘贴到该文件中。 您可以将  `MyTmsAnnotation`  替换为任何其他有效名称。

```JAVA
public @interface MyTmsAnnotation {
    public String value() default "";
}

```

Kotlin:

Procedure: 创建自定义注解

1. 在   项目   工具窗口 ( `Alt+1` (Windows), `⌘ 1` (macOS), `⌘ 1` (IntelliJ IDEA Classic (macOS)), `⌘ 1` (macOS System Shortcuts), `Alt+1` (XWin), `Alt+1` (GNOME), `Alt+1` (KDE), `Alt+1` (Emacs), `Alt+1` (Sublime Text), `⌘ 1` (Sublime Text (macOS)), `Ctrl+Alt+L` (Visual Studio), `⌘ ⌥ L` (Visual Studio (macOS)), `Ctrl+1` (NetBeans), `Alt+1` (Eclipse), `Alt+1` (Eclipse (macOS))) 中，右键点击要在其中创建新类的节点，然后选择  `新建 | Kotlin 类/文件` 。

2. 将以下代码粘贴到该文件中。 您可以将  `MyTmsAnnotation`  替换为任何其他有效名称。

```KOTLIN
annotation class MyTmsAnnotation(val value: String = "")

```

在注释已经在项目中之后，您需要告知 TMS 插件使用该特定注释。

Procedure: 在 TMS 设置中启用注解

1. 按 `Ctrl+Alt+S` (Windows), `⌘ Comma` (macOS), `⌘ Comma` (IntelliJ IDEA Classic (macOS)), `⌘ Comma` (macOS System Shortcuts), `Ctrl+Alt+S` (XWin), `Ctrl+Alt+S` (GNOME), `Ctrl+Alt+S` (KDE), `Ctrl+Alt+S` (Emacs), `Ctrl+Alt+S` (Sublime Text), `⌘ Comma` (Sublime Text (macOS)), `Ctrl+Alt+S` (Visual Studio), `⌘ Comma` (Visual Studio (macOS)), `Ctrl+Alt+S` (NetBeans), `Ctrl+Alt+S` (Eclipse), `⌘ Comma` (Eclipse (macOS)) 打开设置，然后选择  `工具 | TMS | 从代码引用 | Java/Kotlin` 。

2. 点击   添加   ![](https://resources.jetbrains.com.cn/help/img/idea/2026.3/app.expui.general.add.svg) 以添加注释。

![TMS 设置](https://resources.jetbrains.com.cn/help/img/idea/2026.3/aqua_tms_settings.png)

3. 请指定注解类并点击   OK  。

![在设置中启用注解](https://resources.jetbrains.com.cn/help/img/idea/2026.3/aqua_tms_setup_annotation.png)

最后，若要使 IntelliJ IDEA 在单元测试与 TMS 项目之间建立链接，测试需要使用为该项目配置的注释之一进行注释。

Java:

Procedure: 标注单元测试

1. 在编辑器中打开单元测试文件。

2. 在方法定义之前添加一个 TMS 链接注解，如下所示。

```JAVA
// C58439
@MyTmsAnnotation("C58439")
@Test
void TestCase1() {
    Assertions.assertEquals(4, Calculator.multiply(2,2));
}

```

Kotlin:

Procedure: 标注单元测试

1. 在编辑器中打开单元测试文件。

2. 在方法定义之前添加一个 TMS 链接注解，如下所示。

```KOTLIN
// C58439
@MyTmsAnnotation("C58439")
@Test
fun TestCase1() {
    Assertions.assertEquals(4, Calculator.multiply(2,2))
}

```

