SuperAPI AI 工具集

frappe-testing-unit

测试与质量

查看项目

更新于 10-15 22:17

技能介绍

用途:为 Frappe 应用编写单元测试与集成测试,创建测试夹具,并通过 bench run-tests 执行测试,避免因缺少夹具导致的脆弱测试。主要能力:提供测试基类选择决策(v14 仅 FrappeTestCase;v15+ 推荐 UnitTestCase 无数据库访问、IntegrationTestCase 全数据库访问);说明测试文件必须放在 doctype 目录且以 test_ 前缀命名;支持 test_records.json 静态夹具、_test_records 模块内夹具和程序化夹具(用 frappe.flags 防重复);提供 set_user、change_settings、patch_hooks、freeze_time 等上下文管理器,以及权限、白名单方法、生命周期、Mock 外部服务的测试模式;数据库在每测试后自动回滚。使用方式:常用命令包括 bench --site test_site run-tests、--app myapp、--doctype、--test、--module、--profile、--failfast、--junit-xml-output 等;写测试时按模块路径自动探测 doctype。限制与注意:绝不在测试中调用 frappe.db.commit(),绝不依赖测试执行顺序,若直接调用 frappe.set_user() 需在 tearDown 重置,覆写 setUpClass 必须调用 super().setUpClass();不要用 frappe.flags.in_test 跳过校验逻辑。具体安装与版本信息暂未提供。