跳转到内容

Http测试任务

Http测试任务 定义一个 Http 协议测试任务,用于 Http 功能、性能、稳定性和自定义测试。

主参数清单

参数类型必填长度限制说明
targetenum-任务类型标识
固定值 HTTP
namestring≤400 字符接口标识名称
测试场景中的唯一标识
descriptionstring≤800 字符详细功能描述
说明接口业务用途
enabledboolean-启用状态
true:执行该接口(默认)
false:跳过该接口
beforeNamestring≤400 字符执行顺序控制
指定前序任务名称,确保执行顺序
transactionNamestring≤400 字符事务归属标识
关联事务控制器的开始事务名称
apisIdinteger-接口资源关联
关联 API 仓库 ID(测试结果自动回写)
caseIdinteger-测试用例关联
关联测试用例 ID(测试结果自动回写)
requestobject-请求配置
定义请求方法/URL/参数/认证等
assertionsarray[object]-结果验证规则
设置响应校验条件
variablesarray[object]-动态采样变量提取
从响应中提取值供后续使用
查看采样变量定义
datasetsarray[object]-测试数据集
驱动多场景数据测试
查看数据集定义
actionOnEOFenum-数据集结束策略
RECYCLE:循环使用(默认)
STOP_THREAD:停止线程
sharingModeenum-数据共享模式
ALL_THREAD:线程共享(默认)
CURRENT_THREAD:线程独立

关键参数说明:

  1. 事务控制 (transactionName)
    • 用于关联事务控制器(TRANS_START)
    • 实现业务操作原子性统计
  2. 数据驱动 (datasets+sharingMode)
    • ALL_THREAD:所有线程共享同一份数据
    • CURRENT_THREAD:每个线程独立数据副本
  3. 结束策略 (actionOnEOF)
    • RECYCLE:循环使用数据(压测场景)
    • STOP_THREAD:数据用尽停止线程(精准控制)
  4. 结果关联 (apisId/caseId)
    • 实现测试结果自动同步到API仓库/测试用例
    • 支持持续集成报告自动生成

Http完整结构示例:

yaml
- target: HTTP
  name: Add User
  description: This is an example of complete HTTP parameters
  enabled: true
  beforeName: BusinessTransaction
  transactionName: BusinessTransaction
  apisId: 193234753355265004
  caseId: 193234753355265004
  request:
    # 请求参数配置 ...
  assertions:
    # 断言参数配置 ...
  variables:
    # 变量参数配置 ...
  datasets:
    # 数据集参数配置 ...
  actionOnEOF: RECYCLE
  sharingMode: ALL_THREAD

请求构建(request)

参数类型必填限制说明
methodenum-请求方法
POST/GET/PUT/PATCH/
DELETE/HEAD/OPTIONS/TRACE
urlstring≤2000字符完整请求URL
优先级高于server+endpoint组合
serverobject-服务器配置
定义基础URL和环境变量
endpointstring≤800字符接口路径
与server组合构成完整URL
authenticationobject-认证配置
支持Basic/Bearer/APIKey/OAuth2等认证方式
parametersarray1-200项请求参数
Path/Query/Header/Cookie参数配置
bodyobject-请求体配置
支持JSON/Form/二进制等格式

完整 URL、服务器(server)、和端点(endpoint)关系:

txt
https://api.example.com/v1/users?role=admin&status=active
\________________________/\____/ \______________________/
         server URL       endpoint    query parameters
                    完整URL(path)

请求完整示例结构:

yaml
request:
  method: PUT
  url: "http://serv01-sample.angusmock.cloud:30010/user/{username}"
  server:
    # 服务器参数配置 ...
  endpoint: "/user/{username}"
  authentication:
    # 认证参数配置 ...
  parameters:
    # 请求参数配置 ...
  body:
    # 请求体配置 ...

服务器配置(server)

参数类型必填长度限制说明
urlstring≤400字符服务器基础URL
descriptionstring≤800字符服务器描述
说明服务器用途或环境信息
variablesMap<string,serverVariable>1-200项环境变量配置
支持多环境动态切换

服务器配置(serverVariable)

参数类型必填长度限制说明
allowableValuesarray[string]1-200项允许值列表
定义变量可选值范围
defaultValuestring≤400字符默认值
未指定时的默认值
descriptionstring≤800字符变量描述
说明变量用途

服务器配置示例

yaml
server:
  url: "http://{env}-sample.angusmock.cloud:660"
  description: The example of server
  variables:
    env:
      allowableValues:
      - dev
      - beta
      - prod
      defaultValue: beta
      description: The example of server variable

认证配置(authentication)

参数类型必填长度限制说明
typeenum-认证类型
none:无需认证
http:基础认证
apiKey:API密钥
oauth2:OAuth2授权
namestring≤400字符认证方案名称
示例:用户认证/API密钥认证
descriptionstring≤800字符认证方案描述
详细说明认证机制
enabledboolean-启用状态
true:启用(默认)
false:禁用
valuestring≤4096字符认证凭证值
支持变量表达式
示例:Bearer {accessToken}
apiKeysarray1-10项API密钥组
多密钥组合认证
oauth2object-OAuth2配置
支持多种授权流程

认证配置示例结构:

yaml
authentication:
  type: http
  name: Security schema
  description: The security scheme used for HTTP requests
  enabled: true
  value: Bearer 181622ea2a1f4934ad6bec0308390da9
  apiKeys:
    # Api 秘钥认证配置
  oauth2:
   # OAuth2 认证配置

Basic认证(http)

yaml
authentication:
  type: http
  name: Security schema
  description: The security scheme used for HTTP requests
  enabled: true
  value: Basic YWRtaW46YWRtaW4xMjM=  # Base64 username:password

Bearer令牌认证(http)

yaml
authentication:
  type: http
  name: Security schema
  description: The security scheme used for HTTP requests
  enabled: true
  value: Bearer 181622ea2a1f4934ad6bec0308390da9

Api秘钥认证(apiKeys)

参数类型必填长度限制说明
namestring≤400字符参数标识名
支持变量表达式
示例:X-{variable1}-API-Key
inenum-参数位置
header:请求头
query:URL查询参数
cookie:Cookie
valuestring≤1024字符参数值
支持变量表达式
示例:{apiKey}
yaml
type: apiKey
name: Security schema
description: The security scheme used for HTTP requests
enabled: true
apiKeys:
- name: ak
  in: cookie
  value: cLpyeth1YGcZ8iZFJQilCJi4m979D1To
- name: sk
  in: cookie
  value: ypIPSxeI7ylgCW44FIFugZKmld63eQO3xqbGxsVIor3EWqxRgwA1YXtDsVrUwuMX

OAuth2认证(oauth2)

参数类型必填长度限制说明
clientCredentialsobject-客户端凭证模式
适用于服务端间认证
passwordobject≤400字符密码模式
适用于受信任客户端
authFlowenum≤800字符认证流程选择
clientCredentials/password
newTokenboolean-令牌刷新策略
true:每次请求获取新令牌
false:使用固定令牌(默认)
tokenstring条件≤4096字符固定访问令牌
newToken=false时必填
支持变量表达式

使用已有OAuth2访问令牌示例:

yaml
type: oauth2
name: Security schema
description: The security scheme used for HTTP requests
enabled: true
value: Bearer 181622ea2a1f4934ad6bec0308390da9
oauth2:
  authFlow: clientCredentials
  newToken: true
  token: Bearer 181622ea2a1f4934ad6bec0308390da9
OAuth2-clientCredentials 认证流程
参数类型必填长度限制说明
tokenUrlstring≤400字符令牌获取地址
OAuth2 认证核心端点
scopesarray1-200项权限范围
定义API访问权限
示例:["user:read", "user:write"]
clientIdstring≤400字符客户端ID
支持变量表达式
示例:{env}_client_id
clientSecretstring≤1024字符客户端密钥
支持变量表达式
敏感信息建议加密存储
clientInenum-客户端凭证位置
详见下方位置说明

客户端凭证位置说明 (clientIn)

位置传输方式示例
QUERY_PARAMETERURL 参数?client_id=id&client_secret=secret
BASIC_AUTH_HEADERAuthorization 头Basic base64(id:secret)
REQUEST_BODYForm 表单client_id=id&client_secret=secret

客户端凭据证方式示例:

yaml
type: oauth2
name: Security schema
description: The security scheme used for HTTP requests
enabled: true
oauth2:
  clientCredentials:
    tokenUrl: http://serv01-sample.angusmock.cloud:30010/oauth/token
    scopes:
    - user:read
    clientId: client3
    clientSecret: secret3
    clientIn: QUERY_PARAMETER
  authFlow: clientCredentials
OAuth2-password 认证流程
参数类型必填长度限制说明
tokenUrlstring≤400字符令牌获取地址
OAuth2 认证核心端点
scopesarray1-200项权限范围
定义API访问权限
示例:["user:read", "user:write"]
clientIdstring≤400字符客户端ID
支持变量表达式
示例:{env}_client_id
clientSecretstring≤1024字符客户端密钥
支持变量表达式
敏感信息建议加密存储
clientInenum-客户端凭证位置
详见下方位置说明
usernamestring≤400字符用户名
密码模式专用
支持变量表达式
passwordstring≤1024字符密码
密码模式专用
支持变量表达式

资源所有者密码认证方式示例:

yaml
type: oauth2
name: Security schema
description: The security scheme used for HTTP requests
enabled: true
oauth2:
  password:
    tokenUrl: http://serv01-sample.angusmock.cloud:30010/oauth/token
    scopes:
    - user:read
    clientId: client2
    clientSecret: secret2
    clientIn: QUERY_PARAMETER
    username: admin
    password: 123456
  authFlow: password

请求参数(parameters)

参数类型必填长度限制说明
namestring≤400字符参数标识名
支持变量表达式
示例:{env}_id
inenum-参数位置
QUERY:URL查询参数
PATH:URL路径参数
HEADER:请求头
COOKIE:Cookie
descriptionstring≤800字符参数说明
详细描述参数用途
enabledboolean-启用状态
true:包含该参数(默认)
false:忽略该参数
typeenum-数据类型
string/number/integer
/boolean/array/object
默认:string
formatstring≤80字符数据格式
示例:date/email/uuid/uri
valuestring≤4096字符参数值
支持变量和Mock函数
示例:@Email()

注意:RFC7230 声明头名称不区分大小写。

请求参数不同参数位置完整示例:

yaml
parameters:
- name: Authorization
  in: header
  description: The example of parameters in the request header
  enabled: true
  type: string
  format: string
  value: "{accessToken}"
- name: Content-Type
  in: header
  description: Content-Type is used to determine the request content
  enabled: true
  type: string
  format: string
  value: application/json
- name: username
  in: path
  description: The example of parameters in the path
  enabled: true
  type: string
  format: string
  value: admin
- name: password
  in: query
  description: The example of parameters in the query
  enabled: true
  type: string
  format: string
  value: admin

请求体(body)

参数类型必填长度限制说明
formatstring≤80 字符数据格式标识
示例:json/xml/yaml
contentEncodingenum-内容编码
base64:Base64 编码
gzip_base64:GZIP 压缩后 Base64 编码
formsarray1-200 项表单参数组
用于 FormData 格式请求
rawContentstring-原始内容
支持 JSON/XML 文本或二进制 Base64
支持变量和 Mock 函数
Form参数(forms)
参数类型必填长度限制说明
namestring≤400 字符参数名称
表单字段标识
示例:avatar/metadata
descriptionstring≤800 字符参数描述
说明字段用途
enabledboolean-启用状态
true:包含该字段(默认)
false:忽略该字段
typeenum-数据类型
string/number/integer/boolean/array/object
默认:string
formatstring≤80 字符数据格式
示例:date/email/uuid
contentTypestring≤80 字符内容类型
示例:image/png/application/json
contentEncodingenum-内容编码
base64:Base64 编码
gzip_base64:GZIP 压缩后 Base64
fileNamestring≤400 字符文件名
文件上传时使用
示例:avatar.png
valuestring-参数值
支持文本/JSON/Base64 编码文件
支持变量和 Mock 函数

请求体 ContentType 为 application/json 格式示例:

yaml
body:
  format: json
  rawContent: "{\"age\": 18, \"hobbies\": \"swimming, playing basketball\", \"avatar\"\
    :\"http://serv01-sample.angusmock.cloud:30010/user/{username}/avatar.png\"}"

请求体 ContentType 为 application/x-www-form-urlencoded 格式示例:

yaml
body:
  forms:
  - name: age
    description: The example of form-data text parameter
    enabled: true
    type: integer
    format: int32
    value: 18
  - name: hobbies
    description: The example of form-data text parameter
    enabled: true
    type: string
    format: string
    value: "swimming, playing basketball"

请求体 ContentType 为 multipart/form-data 格式示例:

yaml
body:
  forms:
  - name: age
    description: The example of form-data text parameter
    enabled: true
    type: integer
    format: int32
    value: 18
  - name: hobbies
    description: The example of form-data text parameter
    enabled: true
    type: string
    format: string
    value: "swimming, playing basketball"
  - name: avatar
    description: The example of form-data file parameter
    enabled: true
    type: string
    format: string
    contentType: image/png
    contentEncoding: base64
    value: VGhpcyBpcyB0aGUgYmluYXJ5IGNvbnRlbnQgb2YgdGhlIGF2YXRhci5wbmcgZmlsZQ==
    fileName: avatar.png

请求体 ContentType 为二进制 image/png 格式示例:

yaml
body:
  format: binary
  contentEncoding: base64 
  rawContent: VGhpcyBpcyB0aGUgYmluYXJ5IGNvbnRlbnQgb2YgdGhlIGF2YXRhci5wbmcgZmlsZQ==

响应断言(assertions)

参数类型必填长度限制说明
namestring≤200字符断言名称
唯一标识断言
示例:验证状态码
descriptionstring≤800字符断言描述
详细说明断言目的
enabledboolean-启用状态
true:启用(默认)
false:禁用
typeenum-断言类型
STATUS:状态码
HEADER:响应头
BODY:响应体
BODY_SIZE:响应体大小
SIZE:响应大小
DURATION:耗时
parameterNamestring条件≤400字符参数名称
type=HEADER时必填
指定响应头名称
conditionstring≤400字符执行条件
变量表达式控制断言执行
示例:{env} == "prod"
assertionConditionenum-断言条件
详见下方断言条件说明
expressionstring条件≤400字符提取表达式
REGEX/JSON_PATH/XPATH时必填
matchIteminteger1-2000匹配项索引
多值匹配时指定位置
expectedstring条件≤4096字符期望值
非空值条件时必填
extractionobject-动态提取配置
从响应中提取期望值

断言条件(assertionCondition)

条件说明适用类型示例
EQUAL严格相等验证所有类型200 = 200 → 通过
NOT_EQUAL不相等验证所有类型404200 → 通过
IS_EMPTY空值检查(空字符串或 null)字符串/对象""null → 通过
NOT_EMPTY非空值检查字符串/对象"data" → 通过
IS_NULL严格 null 检查对象null → 通过
NOT_NULL非 null 检查对象{} → 通过
GREATER_THAN大于比较数字/日期1024 > 1000 → 通过
GREATER_THAN_EQUAL大于等于比较数字/日期100100 → 通过
LESS_THAN小于比较数字/日期80 < 100 → 通过
LESS_THAN_EQUAL小于等于比较数字/日期100100 → 通过
CONTAIN包含关系字符串/数组"hello world""world" → 通过
NOT_CONTAIN不包含关系字符串/数组"hello""world" → 通过
REG_MATCH正则匹配字符串"abc123" ~ "\d+" → 通过
XPATH_MATCHXML 节点匹配XML//book/price > 50
JSON_PATH_MATCHJSON 节点匹配JSON$.data.userId = "1001"

匹配项规则(matchItem)

场景匹配项设置返回值
未指定索引不设置或 matchItem: null所有匹配值合并为一个字符串
有效索引matchItem: N (0≤N≤2000)返回第N+1个匹配值
无效索引N>匹配项数量返回 null

1. 正则匹配 (REG_MATCH)

输入文本

你好!我的电话是18888888888和13999999999。

表达式

regex
(1\d{10})

匹配结果处理

matchItem返回值说明
未指定"1888888888813999999999"所有匹配值合并
0"18888888888"第一个匹配值
1"13999999999"第二个匹配值
2null超出范围

2. JSONPath匹配 (JSON_PATH_MATCH)

输入JSON

json
{  
  "store": {  
    "book": [  
      {"title": "Book1", "price": 100},  
      {"title": "Book2", "price": 200}  
    ]  
  }  
}

表达式

$.store.book[*]

匹配结果处理

matchItem返回值说明
未指定[{"title":"Book1","price":100},
{"title":"Book2","price":200}]
完整数组
0{"title":"Book1","price":100}第一本书
1{"title":"Book2","price":200}第二本书
2null超出范围

3. XPath匹配 (XPATH_MATCH)

输入XML

xml
<persons>  
  <person>  
    <name>张三</name>  
    <skills>Java</skills>  
    <skills>Python</skills>  
  </person>  
  <person>  
    <name>李四</name>  
    <skills>JavaScript</skills>  
  </person>  
</persons>

表达式

txt
//person

匹配结果处理

matchItem返回值说明
未指定"张三JavaPython李四JavaScript"所有文本合并
0"张三JavaPython"第一个person节点文本
1"李四JavaScript"第二个person节点文本
2null超出范围

提取期望值配置(extraction)

提取可用于从当前请求或者响应中指定位置读取一个值作为断言期望值。

参数类型必填长度限制说明
methodenum-提取方法
REGEX:正则表达式
JSON_PATH:JSON路径
X_PATH:XML路径
expressionstring-提取表达式
根据method类型编写
defaultValuestring-默认值
提取失败时使用
locationenum-提取位置
详见下方位置说明
parameterNamestring条件≤400字符参数名称
location为HEADER/PATH/QUERY/FORM时必填

提取位置(location)

位置适用场景示例
PATH_PARAMETERRESTful资源ID/users/{userId}
QUERY_PARAMETER筛选条件?category=books
REQUEST_HEADER认证信息Authorization: Bearer token
FORM_PARAMETER表单字段username=admin
REQUEST_RAW_BODY原始请求内容JSON/XML请求体
RESPONSE_HEADER响应元数据Content-Type: application/json
RESPONSE_BODY业务数据JSON/XML响应体

期望值断言示例:

yaml
assertions: 
- name: Assert the HTTP status code is `200`
  description: This is an example of an expected value assertion
  enabled: true
  type: STATUS
  expected: 200
  assertionCondition: EQUAL
  condition: 1=1
- name: Assert the business code is `S`
  description: "This is an example of jsonpath match assertions, response body is:\
    \ {\n    \"code\": \"S\",\n    \"msg\": \"Success\"\n}"
  enabled: true
  type: BODY
  expected: S
  expression: $..code
  assertionCondition: JSON_PATH_MATCH
- name: Assert response header `X-Extraction-Token` value contains `888888`
  description: "This is an example of regexp match assertions, `X-Extraction-Token`\
    \ value is: Your token is 888888 or 999999"
  enabled: true
  type: HEADER
  parameterName: X-Extraction-Token
  expected: 888888
  expression: "(\\d{6})"
  matchItem: 1
  assertionCondition: REG_MATCH
  condition: "{assertHeader}=true"

提取值断言示例:

yaml
assertions: 
- name: Assert the response body access_token is `181622ea2a1f4934ad6bec0308390da9`
  description: This is an example of an extraction value assertion
  enabled: true
  type: BODY
  assertionCondition: EQUAL
  extraction:
    method: JSON_PATH
    expression: $.data.access_token
    defaultValue: 181622ea2a1f4934ad6bec0308390da9
    location: RESPONSE_BODY

完整配置参数示例

yaml
- target: HTTP
  name: Add User
  description: This is an example of complete HTTP parameters
  enabled: true
  beforeName: BusinessTransaction
  transactionName: BusinessTransaction
  apisId: 193234753355265004
  caseId: 193234753355265004
  request:
    method: PUT
    url: "http://serv01-sample.angusmock.cloud:30010/user/{username}"
    server:
      url: "http://{env}-sample.angusmock.cloud:660"
      description: The example of server
      variables:
        env:
          allowableValues:
            - dev
            - beta
            - prod
          defaultValue: beta
          description: The example of server variable
    endpoint: "/user/{username}"
    authentication:
      type: http
      name: Security schema
      description: The security scheme used for HTTP requests
      enabled: true
      value: Bearer 181622ea2a1f4934ad6bec0308390da9
      apiKeys:
        - name: ak
          in: cookie
          value: cLpyeth1YGcZ8iZFJQilCJi4m979D1To
        - name: sk
          in: cookie
          value: ypIPSxeI7ylgCW44FIFugZKmld63eQO3xqbGxsVIor3EWqxRgwA1YXtDsVrUwuMX
        - name: otherKey1
          in: header
          value: otherKey1Value
        - name: otherKey2
          in: query
          value: otherKey2Value
      oauth2:
        clientCredentials:
          tokenUrl: http://serv01-sample.angusmock.cloud:30010/oauth/token
          scopes:
            - user:read
          clientId: client3
          clientSecret: secret3
          clientIn: QUERY_PARAMETER
        password:
          tokenUrl: http://serv01-sample.angusmock.cloud:30010/oauth/token
          scopes:
            - user:read
          clientId: client2
          clientSecret: secret2
          clientIn: QUERY_PARAMETER
          username: admin
          password: 123456
        newToken: false
    parameters:
      - name: Authorization
        in: header
        description: The example of parameters in the request header
        enabled: true
        type: string
        format: string
        value: "{accessToken}"
      - name: Content-Type
        in: header
        description: Content-Type is used to determine the request content
        enabled: true
        type: string
        format: string
        value: application/json
      - name: username
        in: path
        description: The example of parameters in the path
        enabled: true
        type: string
        format: string
        value: admin
      - name: password
        in: query
        description: The example of parameters in the query
        enabled: true
        type: string
        format: string
        value: admin
    body:
      type: string
      format: string
      contentEncoding: base64
      forms:
        - name: age
          description: The example of form-data text parameter
          enabled: true
          type: integer
          format: int32
          value: 18
        - name: hobbies
          description: The example of form-data text parameter
          enabled: true
          type: string
          format: string
          value: "swimming, playing basketball"
        - name: avatar
          description: The example of form-data file parameter
          enabled: true
          type: string
          format: string
          contentType: image/png
          contentEncoding: base64
          value: VGhpcyBpcyB0aGUgYmluYXJ5IGNvbnRlbnQgb2YgdGhlIGF2YXRhci5wbmcgZmlsZQ==
          fileName: avatar.png
      rawContent: "{\"age\": 18, \"hobbies\": \"swimming, playing basketball\", \"avatar\"\
        :\"http://serv01-sample.angusmock.cloud:30010/user/{username}/avatar.png\"}"
  assertions:
    - name: Assert the HTTP status code is 200
      description: This is an example of an expected value assertion
      enabled: true
      type: STATUS
      expected: 200
      assertionCondition: EQUAL
      condition: 1=1
    - name: Assert response header `X-Extraction-Token` value contains 888888
      description: "This is an example of extracting value assertions, `X-Extraction-Token`\
      \ value is: Your token is 888888 or 999999"
      enabled: true
      type: HEADER
      parameterName: X-Extraction-Token
      expected: 888888
      expression: "(\\d{6})"
      matchItem: 1
      assertionCondition: EQUAL
      condition: "{assertHeader}=true"
  variables:
    - name: accessToken
      method: JSON_PATH
      expression: $.data.access_token
      location: RESPONSE_BODY
  datasets:
    - name: UsernameDataset
      parameters:                             
        - name: username                             
          value: '@Name()'
  actionOnEOF: RECYCLE
  sharingMode: ALL_THREAD

基于 GPL-3.0 许可发布