# @autorest/testmodeler 中文文档

规范地址：https://npmcn.com/package/%40autorest/testmodeler/

版本：2\.6\.4-ci\.254802bfc\.0
npm 元数据更新时间：2025-06-26T09:37:24.101Z
中文译文更新时间：2026-11-07T07:08:31.236Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40autorest/testmodeler
原文对照：https://npmcn.com/package/%40autorest/testmodeler/?lang=original
项目主页：https://github.com/Azure/azure-sdk-tools#readme
源码仓库：https://github.com/Azure/azure-sdk-tools

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：133 kB，31 个文件
- 模块格式：CommonJS
- TypeScript 类型：包内自带
- 运行依赖：26 个
- 首次发布：2021-10-27T10:33:27.821Z
- 最新版本发布：2025-06-26T09:37:23.878Z
- 近 30 天下载量：6952（2026-10-07 至 2026-11-05，npm 官方下载统计）
- 已发布版本数：29（近 12 个月 0 个）

## 中文简介

测试模型自动扩展

## 安装

```sh
npm install @autorest/testmodeler
```

也可以使用：`pnpm add @autorest/testmodeler`、`yarn add @autorest/testmodeler`、`bun add @autorest/testmodeler`

## README

# 自动回复 SDK 测试生成工具

* * *

## 软件包

| 名称 | 更改日志 | 最新 |
| --- | --- | --- |
| [@ autorest/ 测试模型](https://npmcn.com/package/%40autorest/testmodeler/packages/autorest.testmodeler) | [更改日志](https://npmcn.com/package/%40autorest/testmodeler/packages/autorest.testmodeler/CHANGELOG.md) | ![](https://img.shields.io/npm/v/@autorest/testmodeler) |
| [@autorest/获得](https://npmcn.com/package/%40autorest/testmodeler/packages/autorest.gotest) | [更改日志](https://npmcn.com/package/%40autorest/testmodeler/packages/autorest.gotest/CHANGELOG.md) | ![](https://img.shields.io/npm/v/@autorest/gotest) |

## 捐款

关于克隆/建筑/etc的说明,见 [发展](https://npmcn.com/package/%40autorest/testmodeler/docs/development.md)

### 捐助者许可证协议要求

该项目欢迎各方的贡献和建议。 大多数捐款要求您同意 撰稿人许可协议(CLA)宣布,你有权并且实际上确实给了我们 有权使用您的贡献。 详情请访问 [https://cla.microsoft.com (中文(简体) )](https://cla.microsoft.com/)。 。 。 .

当您提交拉动请求时, CLA 机器人会自动确定您是否需要提供 a CLA并适当装饰公关(例如标签、评论)。 只要听从指示 由机器人提供。 你只需要用我们的CLA 一次就能完成.

### 行为守则

该项目通过了 [Microsoft 开源行为守则](https://opensource.microsoft.com/codeofconduct/)。 。 。 . 更多信息见 [《行为守则》](https://opensource.microsoft.com/codeofconduct/faq/) 或者说 联系人 [打开码@ microsoft.com](mailto:opencode@microsoft.com) 并附上任何其他问题或评论.

# 测试模型自动扩展

以 Azure REST API 规格生成 \*. md 配置文件 :

[https://github.com/Azure/azure-rest-api-specs (中文(简体) )](https://github.com/Azure/azure-rest-api-specs)

## 如何生成测试模型

```
autorest --version=3.7.3 --use=<test model extension> --output-folder=<RP package path> --testmodeler.export-codemodel --clear-output-folder=false --debug <RP config md file path>
```

## 捐款

测试模型使用匆忙管理项目. 所以如果软件包有变化,请记住执行 `rush update` 更新.

```
> rush update
```

## 配置

以下选项可用于自動取回. 测试模型

### \-- 调试

在 \[output-foler\]/ debuger中生成建模器文件,用于调试目的.

### \--testmodeler.mock.send-example-id (中文(中国大陆) )

在生成的模拟测试中, 发送 swagger example- id 在每次请求中模拟服务主机 。 这隐含地要求模拟服务主机通过浏览示例内容来验证请求正文. 默认真实.

### \--testmodeler.mock. 验证-反应

在生成的模拟测试中,会用示例文件验证响应值. 默认真实.

### \--testmodeler.mock. 残疾实例

这是一个数组参数可以在自定义读取文件中指定 . 例如, extensions Get and Extensions Delete 将不会在模拟测试生成中使用, 配置如下 .

```
testmodeler:
    mock:
        disabled-examples:
            - Extensions_Get
            - Extensions_Delete
```

### \--testmodeler.scenario. 变相默认. 位置

设定情景测试中使用的位置, 例如 :

```
testmodeler:
    scenario:
        variable-defaults:
            location: eastus
```

### \--testmodeler.scenario.codemodel - restcall - 仅限使用

如果readme文件中没有定义"test-resources",并且readme位于本地文件系统中,测试模型将搜索所有可用的api-scenario,并尝试将其加载为测试情景. 在这种情况下,选项编码-restcall-只定义了测试模型是否放弃了包含不能与代码模型中的操作相链接的休息步骤的api-screenarios.

此选项的默认值为真 .

### \--testmodeler.use-example-model 互联网档案馆的存檔,存档日期2011-12-02

此选项会切换是否在测试模型中生成示例模型 。 默认为真实时, 它可以像下面这样被禁用 :

```
testmodeler:
    use-example-model: false
```

### \--testmoder.ad-art-template-pairload-string 中标

此选项可切换是否将 StepArmTemplate Model.armTemplatePayloadString 添加到测试模型中 。 虽然默认是虚假的,但可以像下面这样启用:

```
testmodeler:
    add-armtemplate-payload-string: true
```

### \--testmoder.api-scoreario-loader - 选项

Api-scasearios默认从自定义输入文件中加载. 此选项提供了一个从其他远程/ 分支/ 承诺中装入 api- scenario 的门 . 此选项直接传递到 oav 情景加载器, 参见 [https://github.com/Azure/oav/blob/develop/lib/apiScenario/apiScenarioLoader.ts#L60 (中文(简体) )](https://github.com/Azure/oav/blob/develop/lib/apiScenario/apiScenarioLoader.ts#L60) 更详细一些 此选项的样本 :

```
testmodeler:
    api-scenario-loader-option:
        fileRoot: https://github.com/Azure/azure-rest-api-specs/blob/eb829ed4739fccb03dd2327b7762392e74c80ae4/specification/appplatform/resource-manager
        swaggerFilePaths:
          - 'Microsoft.AppPlatform/preview/2020-11-01-preview/appplatform.json'
```

### \--测试资源

Api-scenario的列表想要被加载到测试模型中. 以下是一个样本:

```
test-resources:
    - test: Microsoft.AppPlatform/preview/2020-11-01-preview/scenarios/Spring.yaml
```

### \--testmoder.export-explict-type 互联网档案馆的存檔,存档日期2013-12-02

是否在原始类型上导出带有标签的代码模型, 默认为虚假 。 显示输出值 :

```
// with primitive types:
isDataAction: !!bool false
count: !!int 64


// with no types:
isDataAction: false
count: 64
```

### \--testmodeler.explient-types (英语)

当出口-显性类型属实时,需要明确标记类型清单。 默认的明文Types是 \['bool','int','float','timestamp'\]. 试验发电机可以改变如下:

```
testmodeler:
    explicit-types:
        - bool
        - int
        - float
```

## 自动恢复管道配置

```yaml
clear-output-folder: false

try-require:
    - ./readme.test.md
    - ./readme.testmodeler.md

version: 3.9.7

use-extension:
  "@autorest/modelerfour" : "4.25.0"

pipeline:
    test-modeler:
        input: modelerfour/identity
        output-artifact: source-file-test-modeler
    testmodeler/emitter:
        input: test-modeler
        scope: scope-testmodeler/emitter

scope-testmodeler/emitter:
    input-artifact:
        - source-file-test-modeler
    output-uri-expr: $key
    
testmodeler:
    split-parents-value: true
```

```yaml
testmodeler:
    export-codemodel: true
```

## 常见问题

### @autorest/testmodeler 是什么？

测试模型自动扩展

### 如何安装 @autorest/testmodeler？

在项目目录运行 npm install @autorest/testmodeler，或使用 pnpm add / yarn add / bun add。

### @autorest/testmodeler 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @autorest/testmodeler 支持 ESM 还是 CommonJS？

以 CommonJS 形式发布，可以直接 require\(\)；在 ES Module 项目中也可以用 import 引入（Node\.js 会把 module\.exports 作为默认导出）。

### @autorest/testmodeler 可以商用吗？

@autorest/testmodeler 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @autorest/testmodeler 的下载量有多少？

根据 npm 官方下载统计，@autorest/testmodeler 在 2026/10/07 – 2026/11/05 这 30 天内被下载 6,952 次，日均约 232 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @autorest/testmodeler 还在维护吗？

最新版本 2\.6\.4-ci\.254802bfc\.0 发布于 2025/06/26（1\.4 年前）；至今共发布 29 个版本，其中过去 12 个月发布了 0 个；首次发布于 2021/10/27。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

