# 加速测试索引

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

测试索引是最耗费 CPU 和时间的 IDE 操作之一。 为了加速这一过程，您可以使用 CLion 的测试作用域检测机制或手动创建测试作用域。 无论哪种方式，在您拥有测试作用域后，只有该作用域过滤的文件会在测试索引过程中被处理。

## 自动测试作用域检测

CLion 可以识别项目中的测试文件并自动创建测试作用域。

> **Note:**
> 自动测试检测仅适用于 [CMake](quick-cmake-tutorial.html) 项目。

Procedure:

1. 从主菜单中选择  `帮助 | 查找操作`  ( `Ctrl+Shift+A` (Windows), `⌘ ⇧ A` (macOS), `⌘ ⇧ A` (IntelliJ IDEA Classic (macOS)), `⌘ ⇧ P` (macOS System Shortcuts), `Ctrl+Shift+A` (XWin), `Ctrl+Shift+A` (GNOME), `Ctrl+Shift+A` (KDE), `Escape, X` (Emacs), `Ctrl+Shift+P` (Sublime Text), `⌘ ⇧ P` (Sublime Text (macOS)), `⌘ ⇧ A` (Xcode), `Ctrl+Shift+A` (Visual Studio), `⌘ ⇧ A` (Visual Studio (macOS)), `Ctrl+Shift+A` (ReSharper), `⌘ ⇧ A` (ReSharper (macOS)), `Ctrl+Shift+A` (QtCreator), `⌘ ⇧ A` (QtCreator (macOS)), `Ctrl+I` (NetBeans), `Ctrl+Shift+A` (Eclipse), `⌘ 3` (Eclipse (macOS)))，然后搜索  创建测试作用域 ：

![在“查找操作”中创建测试作用域](https://resources.jetbrains.com/help/img/idea/2026.3/cl_testscope_findaction.png)

2. CLion 会在气泡中显示测试检测结果：

![测试作用域检测结果](https://resources.jetbrains.com/help/img/idea/2026.3/cl_testscope_baloon.png)

3. 点击   查看更改   打开查看器，您可以在其中检查当前模式（如果之前已检测到或 [手动配置](#create-tests-scope)）和新模式：

![测试文件模式差异查看器](https://resources.jetbrains.com/help/img/idea/2026.3/cl_testscope_diffviewer.png)

4. 点击   应用新的测试作用域  。 在打开的   作用域   对话框中，您可以检查并调整自动检测的模式：

![自动创建的测试作用域](https://resources.jetbrains.com/help/img/idea/2026.3/cl_testscope_autoscope.png)

请点击   Apply   以保存更改。

5. CLion 还会在编辑器中打开测试作用域创建报告：

![测试作用域创建报告](https://resources.jetbrains.com/help/img/idea/2026.3/cl_testscope_report.png)

Procedure: 手动创建测试作用域

1. 转到  `设置 | 外观与行为 | 作用域` 。

2. 请点击   添加作用域  按钮( ![添加作用域按钮](https://resources.jetbrains.com/help/img/idea/2026.3/app-client.expui.general.add.svg))，然后选择您要定义的作用域类型： [local](null)或 [shared](null)。

> **Tip:**
> 在 [文件作用域](configuring-scopes-and-file-colors.html#shared-sc) 中了解更多关于共享作用域的信息。

3. 为新作用域设置以下名称：  Tests 。

您可以在  `设置 | 高级设置 | 测试索引任务`  中配置其他名称：

![测试作用域名称](https://resources.jetbrains.com/help/img/idea/2026.3/cl_testsscope_name.png)

4. 为作用域指定基于文件或文件夹的模式。 CLion 会在项目树窗格中高亮显示匹配的文件：

![测试作用域](https://resources.jetbrains.com/help/img/idea/2026.3/cl_testsscope_matchingfiles.png)

5. 点击   Apply   保存  Tests  作用域。 从此时起，只有此作用域定义的文件会在  测试索引  阶段被索引。

您可以使用  Tests  作用域过滤项目视图，并快速访问项目中的测试文件：

![项目视图中的测试作用域](https://resources.jetbrains.com/help/img/idea/2026.3/cl_testsscope_projectview.png)

## See also

### 教程

[单元测试教程](unit-testing-tutorial.html)

### 操作指南

[性能优化提示](performance-tuning-tips.html)

