# 使用分段进行测试

分段让你可以通过在模拟用户上定义声明来测试你设置的条件。

例如，你可能只想向测试版用户显示某个页面或部分。通过创建一个分段并定义与这组模拟用户相关联的属性，你可以模拟一个特定于你所针对用户的分段。

<figure><img src="/files/e0f6b2827b58e89fcbc6456fd10cfa45f32754ec" alt="A GitBook screenshot showing the segment editor"><figcaption><p>GitBook 中的分段编辑器。</p></figcaption></figure>

### 创建分段

要创建一个新分段，请前往条件编辑器，并点击设置图标 <picture><source srcset="/files/CG9bVSmdbJnQxrYiNbRI" media="(prefers-color-scheme: dark)"><img src="/files/9bcd313f64920f73d3606c61b9fbde5ddf8e3f6b" alt="The Settings icon in GitBook"></picture> ，位于分段下拉菜单中现有分段的旁边。

在这里，你可以定义将显示在模拟用户上的数据。因为这里表示的是这些数据， `visitor.claims` 所以会省略键。

#### 示例

要按照我们文档中的示例为测试版用户创建一个分段，你可以新建一个分段，并添加以下数据。

```json
{
  "isBetaUser": true
}
```

当返回条件编辑器时，选择我们创建的测试版分段应该会显示我们正在查看的页面 **将会** 对我们的测试用户可访问。

<figure><img src="/files/13837c3992e589c7760b2e916caa26212232622a" alt="A GitBook screenshot showing how to test a segment"><figcaption><p>在 GitBook 中测试分段。</p></figcaption></figure>

### 检测到的分段

检测到的分段可让你了解从网站访客那里接收到的声明类型。

这些分段不可编辑，但允许你从分段编辑器中复制/粘贴声明，以创建你自己的用户分段。

### 在预览中测试分段

除了在分段编辑器中测试分段之外，当查看你网站的更改时，你还可以在预览中实时使用你的分段。

在你网站的预览模式下，使用左上角的下拉菜单选择一个分段，以查看你的网站在所选分段下的显示效果。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://gitbook.com/docs/documentation/zh/zhan-dian-fang-wen/adaptive-content/testing-with-segments.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
