
Security News
OWASP 2025 Top 10 Adds Software Supply Chain Failures, Ranked Top Community Concern
OWASP’s 2025 Top 10 introduces Software Supply Chain Failures as a new category, reflecting rising concern over dependency and build system risks.
ApiMeter 是一个简洁优雅、功能强大的 HTTP(S) 接口测试框架,基于 httprunner.py 扩展,实现只需编写维护一份 YAML/JSON 脚本,便可高效实现接口自动化测试、性能测试、线上监控、持续集成等多种测试需求。Enjoy! ✨ 🚀 ✨
validate校验方式需要记忆各种校验器语法,功能有限:
validate:
- eq: ["status_code", 200]
- len_eq: ["content.token", 16]
- eq: ["content.success", true]
script校验方式支持任意 Python 脚本,零学习成本:
script:
# 直接使用 Python assert 语句
- assert status_code == 200
- assert len(content.token) == 16
- assert content.success is True
# 支持复杂条件判断
- |
if status_code == 200:
assert content.success is True
else:
assert content.error_code is not None
# 支持循环校验
- |
for item in content.items:
assert item.get("id") is not None
# 性能校验
- assert elapsed.total_seconds < 2.0
# 调用自定义函数
- ${validate_user_data(content.user)}
核心特性:
支持列表参数:
request:
json:
# 传递列表参数
sign: ${get_sign_v2([$device_sn, $os_platform, $app_version])}
支持字典参数:
request:
json:
# 传递字典参数
sign: "${get_sign_v3({device_sn: $device_sn, os_platform: $os_platform, app_version: $app_version})}"
支持复杂嵌套对象:
script:
# 传递复杂配置对象
- "${check_nested_list_fields(content, {list_path: productList, nested_field: sku, check_fields: [id, amount, currency]})}"
支持链式参数 + 通配符 + 正则表达式:
script:
# 通配符批量校验
- ${check(content, data.product.purchasePlan.*.sku.*.id, data.product.purchasePlan.*.sku.*.amount)}
# 正则表达式和类型校验
- ${check(content, '_url ~= ^https?://[^\s/$.?#].[^\s]*$', 'default_currency =* [USD, CNY]', 'product @= dict')}
无缝访问响应数据,无需特殊语法:
script:
# 直接访问全局变量(无需 $ 前缀)
- assert status_code == 200
- assert headers["Content-Type"] == "application/json"
- assert content.user.name is not None
- assert cookies.session_id is not None
# 支持链式取值(深层数据访问)
- assert content.data.user.profile.age > 18
- assert content.items[0].price > 0
支持变量转义,解决字段名与全局变量冲突:
script:
# \content 会被解析为字符串 "content",而不是全局变量 content
- ${check_field_exists(data, \content)}
可用的全局变量:
status_code, headers, cookies, content, body, json, elapsed, ok, reason, url, response
智能内容折叠:
JSON 树形展示:
Script 执行结果展示:
报告优化选项:
# 报告中跳过成功用例(仅显示失败和错误,减小报告体积)
hrun testcases/ --html report.html --skip-success
pip install apimeter
安装后可用命令:apimeter、meter、api、hrun、apilocust
创建测试文件 test_api.yml:
config:
name: "快速开始示例"
variables:
base_url: "https://httpbin.org"
teststeps:
- name: GET 请求测试
request:
url: $base_url/get
method: GET
params:
name: "ApiMeter"
script:
- assert status_code == 200
- assert json.args.name == "ApiMeter"
- assert json.url.startswith("https://httpbin.org")
- name: POST 请求测试
request:
url: $base_url/post
method: POST
json:
username: "test_user"
email: "test@example.com"
script:
- assert status_code == 200
- assert json.json.username == "test_user"
- |
# 复杂校验逻辑
if json.json.email:
assert "@" in json.json.email
# 基础运行
apimeter test_api.yml
# 优化报告(跳过成功用例)
apimeter test_api.yml --skip-success
在线文档:https://zhuifengshen.github.io/APIMeter/
| 特性 | 传统工具/HttpRunner | ApiMeter |
|---|---|---|
| 校验能力 | 固定校验器语法 | ✅ Python 脚本,无限可能 |
| 学习成本 | 需记忆特定语法 | ✅ 标准 Python,零学习成本 |
| 复杂逻辑 | 有限支持 | ✅ 完全支持(条件、循环、函数) |
| 错误处理 | 单点失败中断 | ✅ 逐条执行,容错处理 |
| 全局变量 | 有限的变量访问 | ✅ 链式取值 + 变量转义 |
| 函数参数 | 简单参数 | ✅ 列表/字典/嵌套对象/通配符 |
| 测试报告 | 基础展示 | ✅ 智能折叠 + JSON树形展示 |
| 数据校验 | 单一固定模式 | ✅ 自定义任意校验逻辑 |
| 调试能力 | 基础日志 | ✅ 详细执行结果和错误信息 |
script:
# 根据用户类型进行不同校验
- |
if content.user.type == "vip":
assert content.user.vip_level > 0
assert content.user.discount >= 0.8
elif content.user.type == "premium":
assert content.user.premium_expires is not None
else:
assert content.user.ads_enabled is True
script:
# 校验商品列表中的每个商品
- |
assert len(content.products) > 0
for product in content.products:
assert product.get("id") is not None
assert product.get("price") > 0
assert product.get("status") in ["active", "inactive"]
if product.get("discount"):
assert 0 < product["discount"] < 1
request:
json:
# 传递复杂参数生成签名
sign: "${generate_signature({
method: $method,
url: $url,
timestamp: $timestamp,
nonce: $nonce,
body: $request_body
})}"
script:
# 同时校验功能和性能
- assert status_code == 200
- assert content.success is True
- assert elapsed.total_seconds < 1.0, f"响应时间过长: {elapsed.total_seconds}s"
- assert len(content.items) <= 100, "返回数据量过大"
如果你在使用过程中遇到问题,欢迎提交 Issue:
🧩 欢迎提交 Pull Request,让 ApiMeter 变得更好!
⭐ 如果 ApiMeter 对你有帮助,请给个 Star 支持一下!
🚀 现在就开始你的 API 自动化测试之旅吧! → 10分钟快速上手
ApiMeter 基于以下优秀的开源项目:
Copyright (c) 2025 Devin Zhang
This software is based on httprunner.py,
which is licensed under the Apache License, Version 2.0.
This project continues to be distributed under the same license.
You may obtain a copy of the License at:
FAQs
One-stop solution for HTTP(S) testing.
We found that apimeter demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OWASP’s 2025 Top 10 introduces Software Supply Chain Failures as a new category, reflecting rising concern over dependency and build system risks.

Research
/Security News
Socket researchers discovered nine malicious NuGet packages that use time-delayed payloads to crash applications and corrupt industrial control systems.

Security News
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.