SuperAPI AI 工具集

godot

测试与质量

查看项目

更新于 10-16 02:24

技能介绍

用途

本技能用于开发、测试、构建和部署 Godot 4.x 游戏,重点覆盖测试自动化与构建部署环节。

主要能力

测试框架

  • GdUnit4:单元测试框架,测试以 GDScript 编写并在 Godot 内部运行。作为 addon 安装,项目结构通常为 addons/gdUnit4、test/、scripts/。支持断言(相等、真值、数值区间、字符串包含、数组大小、信号发射等)、场景运行器(GdUnitSceneRunner)以及输入模拟。
  • PlayGodot:游戏自动化框架,Python 编写,类似 Playwright 之于游戏,从外部通过原生 RemoteDebugger 协议控制 Godot 游戏。适合 E2E/集成测试,需要定制 Godot fork(Randroids-Dojo/godot 的 automation 分支)与 PlayGodot Python 库。

能力对比

GdUnit4 PlayGodot
类型 单元测试 游戏自动化
语言 GDScript Python
运行位置 Godot 内部 外部(类似 Playwright)
依赖 Addon 定制 Godot fork
适用 单元/组件测试 E2E/集成测试

输入与交互模拟

GdUnit4 场景运行器支持鼠标位置设置、按下/释放鼠标键、按键(含组合键如 Ctrl+S)、输入动作按下/释放,以及等待输入处理、空闲帧和信号。PlayGodot 支持点击、双击、右键、拖拽、按键、文本输入、输入动作、触摸(tap/swipe/pinch)、截图、截图对比与断言、场景管理、暂停/时间缩放、等待节点/可见性/信号等。

构建与部署

  • Web 导出:godot --headless --export-release "Web" ./build/index.html,需 export_presets.cfg 中配置 Web 预设。
  • 部署到 Vercel:vercel deploy ./build --prod。
  • CI/CD:GitHub Actions 示例使用 chickensoft-games/setup-godot@v2(version 4.3.0,include-templates: true),运行 GdUnit4 测试并上传报告产物。

使用方式

GdUnit4

安装:git clone --depth 1 https://github.com/MikeSchulze/gdUnit4.git addons/gdUnit4,并在 Project Settings → Plugins 启用插件。 运行全部测试:godot --headless --path . -s res://addons/gdUnit4/bin/GdUnitCmdTool.gd --run-tests;指定测试文件加 --add res://test/my_test.gd;生成报告加 --report-directory ./reports。

PlayGodot

安装:创建虚拟环境后 pip install playgodot;构建定制 Godot fork(如 macOS Apple Silicon:scons platform=macos arch=arm64 target=editor -j8)。配置 conftest.py 提供 game fixture,使用 pytest 编写测试,设置 GODOT_PATH 后运行 pytest tests/ -v。

适用场景

  • 需要 GDScript 单元测试与组件测试的 Godot 项目。
  • 需要从外部驱动游戏进行 E2E、集成测试或自动化游玩的场景。
  • Web 构建与 Vercel 部署,以及 CI 中运行测试并收集报告。

限制

PlayGodot 需要定制 Godot fork(automation 分支)并使用 Randroids-Dojo/godot,依赖较重;GdUnit4 需安装 addon 并启用插件。文档未提供具体收费或价格信息。参考资料包括 references/gdunit4-quickstart.md、scene-runner.md、assertions.md、playgodot.md、deployment.md、ci-integration.md。