用途:为 Frappe v15 应用补充测试覆盖。适用于为已有代码添加测试、为新 DocType/API/服务编写测试、搭建测试夹具与工厂、编写带数据库的集成测试以及不依赖数据库的单元测试。
触发与用法:以 /frappe-test <target> [--type <unit|integration|e2e>] [--coverage] 调用,例如 /frappe-test SalesOrder、/frappe-test inventory_service --type unit、/frappe-test api.orders --type integration --coverage。
主要能力:先分析测试目标(DocType 控制器钩子与校验、Service 业务逻辑、Repository 数据访问、API 端点、工具函数),再按组件类型选择单元/集成/E2E 策略;生成 tests 目录结构(conftest.py、factories、unit/integration/e2e);生成会话/模块/函数级 pytest 夹具,如 as_user、as_guest、rollback_db、API 凭证与断言助手;提供工厂模式(build/create/create_batch/create_submitted/create_with_items)及唯一序号生成器;生成集成测试类,覆盖 CRUD、业务逻辑(提交/取消)、权限校验等场景。
运行方式:使用 bench --site test_site run-tests --app <app> 运行,可用 -k 过滤或指定 --module。
限制:资料未提供安装方式、收费信息、支持平台及具体版本兼容范围;上述步骤为模板化流程,落地时需按实际应用与 DocType 调整占位符内容。