Skip to main content

ApiTestGen

API 测试数据自动生成工具 - 从 JSON Schema / OpenAPI 生成正向和负向测试用例。

功能特性

  • 从 JSON Schema 自动生成正向测试数据
  • 从 OpenAPI 规范自动生成测试数据
  • 生成多场景测试用例(展开布尔值、枚举、逻辑分支)
  • 自动生成负向测试用例(类型错误、约束违反、边界值等)
  • 数据校验功能
  • 支持标签过滤(F1-F7 负向用例分类)

安装

pip install apitestgen

快速开始

Python API

from apitestgen import generate, generate_negative, generates, validate

schema = {
    "type": "object",
    "properties": {
        "name": {"type": "string", "minLength": 2},
        "email": {"type": "string", "format": "email"},
        "age": {"type": "integer", "minimum": 0, "maximum": 150},
    },
    "required": ["name", "email"],
}

# 生成正向数据
data = generate(schema)

# 生成负向用例
neg_cases = generate_negative(schema)

# 多场景生成
scenarios = generates(schema, options={"expand_bool": True, "expand_enum": True})

# 校验数据
result = validate(data, source=schema)

命令行

# 生成正向测试数据
apitestgen generate schema.json

# 生成负向用例
apitestgen negative schema.json

# 多场景生成
apitestgen generates schema.json --expand-bool --expand-enum

# 校验数据
apitestgen validate schema.json data.json

# 生成完整测试集
apitestgen full schema.json

依赖

  • Python >= 3.9
  • jsonschema >= 4.0
  • faker >= 20.0
  • rstr >= 3.0

许可证

MIT License

Release files for apitestgen 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for apitestgen 2.0.0
File Size Uploaded
apitestgen-2.0.0.tar.gz 37.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for apitestgen 2.0.0
File Interpreter ABI Platform
apitestgen-2.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 88.0 kB

Release files / apitestgen-2.0.0.tar.gz

Download URL apitestgen-2.0.0.tar.gz
Size 37.8 kB
Tags Source
SHA-256 checksum
How to use checksums
c5df483ad7a698340ac87af99a7642b0451ac661a8ea03851afa0e3fbd53b9df
BLAKE2b-256 checksum
How to use checksums
982359c840c11df36a1ea8572b71404b4532040cf75bd480d36a3f96b895149b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.5

Release files / apitestgen-2.0.0-py3-none-any.whl

Download URL apitestgen-2.0.0-py3-none-any.whl
Size 50.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b60a18ac23177766687288d09b988f85e80cd8b01ac4629da6808df59ac7b488
BLAKE2b-256 checksum
How to use checksums
867fab79273b4e522f0eba8d0c33f48b67b09872dce42956088736b4a6ff2730
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.5

Release history Release notifications | RSS feed

This release

2.0.0 This release

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page