schemathesis/schemathesis

GitHub: schemathesis/schemathesis

一个基于 OpenAPI/GraphQL Schema 自动生成测试用例的属性驱动 API 测试框架,用于在开发阶段发现 API 边缘情况和健壮性问题。

Stars: 3080 | Forks: 199

Build Coverage Version Python versions Discord License

## Schemathesis Schemathesis 自动根据您的 OpenAPI 或 GraphQL schema 生成数千个测试用例,并找出导致 API 崩溃的边缘情况。

Schemathesis automatically finding a server error
Finding bugs that manual testing missed

## 立即尝试 ``` # 测试 demo API - 在 30 秒内发现真实 bug uvx schemathesis run https://example.schemathesis.io/openapi.json # 测试您自己的 API uvx schemathesis run https://your-api.com/openapi.json ``` ## 它解决了哪些问题? - 💥 **500 错误**:边缘情况输入导致 API 崩溃 - 📋 **Schema 违规**:API 返回的数据与文档记录不符 - 🚪 **校验绕过**:无效数据被接受 - 🔗 **集成失败**:响应与客户端期望不匹配 - 🔄 **有状态 Bug**:单独操作正常,但在实际工作流中失败 # 安装与使用 **命令行:** ``` uv pip install schemathesis schemathesis run https://your-api.com/openapi.json ``` **Python 测试:** ``` import schemathesis schema = schemathesis.openapi.from_url("https://your-api.com/openapi.json") @schema.parametrize() def test_api(case): # Tests with random data, edge cases, and invalid inputs case.call_and_validate() # 有状态测试:测试工作流,例如:create user -> get user -> delete user APIWorkflow = schema.as_state_machine() # 为 pytest/unittest 创建测试类 TestAPI = APIWorkflow.TestCase ``` **CI/CD:** ``` - uses: schemathesis/action@v2 with: schema: "https://your-api.com/openapi.json" ``` ## 谁在使用 被 **[Spotify](https://github.com/backstage/backstage)**、**[WordPress](https://github.com/WordPress/openverse)**、**JetBrains**、**Red Hat** 以及许多其他公司的团队使用。 ## 查看实际运行效果 🔬 **[实时基准测试](https://workbench.schemathesis.io)** 展示了来自真实世界 API 的持续测试结果: - 代码与 API schema 覆盖率 - 发现的问题及详细分类 - 不同 fuzzing 策略的性能表现 ## 文档 📚 **[文档](https://schemathesis.readthedocs.io/en/stable/)** 包含指南、示例和 API 参考。 ## 获取帮助 - 💬 [Discord 社区](https://discord.gg/R9ASRAmHnA) - 🐛 [GitHub issues](https://github.com/schemathesis/schemathesis/issues) ## 致谢 Schemathesis 构建于 Hypothesis 之上,这是一个强大的 Python 基于属性的测试库。 ## 许可证 本项目采用 [MIT 许可证](https://opensource.org/licenses/MIT) 授权。
标签:500错误检测, API密钥检测, API测试, GraphQL, LNA, OpenAPI, Python, Schemathesis, Schema验证, Web安全, 威胁情报, 安全规则引擎, 开发者工具, 文档结构分析, 无后门, 蓝队分析, 质量保证, 输入验证, 边缘用例, 逆向工具, 集成测试