patrol-setup
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePatrol setup
Patrol 配置
Get a first Patrol test passing on an Android emulator. Tell the user up front that
this covers Android only (the pubspec block + native Android); iOS and
other platforms follow the same install doc but aren't part of this first setup.
patrol:This skill is the ordered process and the gotchas; the canonical docs are the source
of truth for versions, native config, and code — follow them at each step instead of
guessing:
- Install + native setup (dependencies, the block, Android, iOS, flavors) — https://patrol.leancode.co/documentation
patrol: - Write your first test — https://patrol.leancode.co/documentation/write-your-first-test
让首个Patrol测试在Android模拟器上运行通过。提前告知用户,本文仅覆盖Android平台(包括pubspec中的块 + 原生Android配置);iOS及其他平台的配置流程与本文一致,但不在本次初始配置范围内。
patrol:本技能涵盖了有序的操作流程及常见陷阱;官方文档是版本、原生配置及代码的权威来源——请在每个步骤中遵循官方文档指引,而非自行猜测:
- 安装与原生配置(依赖、块、Android、iOS、构建变体)——https://patrol.leancode.co/documentation
patrol: - 编写首个测试——https://patrol.leancode.co/documentation/write-your-first-test
1. Configure Patrol
1. 配置Patrol
Follow the Setup steps, deep-linking to the relevant point:
- Add the dev dependency and the
patrolblock inpatrol:— https://patrol.leancode.co/documentation#add-patrol-dependencypubspec.yaml - Native Android (test runner, orchestrator, ) — https://patrol.leancode.co/documentation#android-setup (Groovy build files: https://patrol.leancode.co/documentation#old-android-setup)
MainActivityTest.java - Build flavors, if the project uses them — https://patrol.leancode.co/documentation#flavors
遵循设置步骤,可点击链接跳转到对应细节:
- 在中添加
pubspec.yaml开发依赖及patrol块——https://patrol.leancode.co/documentation#add-patrol-dependencypatrol: - 原生Android配置(测试运行器、协调器、)——https://patrol.leancode.co/documentation#android-setup (Groovy构建文件:https://patrol.leancode.co/documentation#old-android-setup)
MainActivityTest.java - 如果项目使用构建变体,请参考——https://patrol.leancode.co/documentation#flavors
2. Write a first minimal test
2. 编写首个最简测试
Follow write your first test for the current API:
https://patrol.leancode.co/documentation/write-your-first-test
Keep this first one self-contained — only Flutter framework widgets, no app or
backend dependencies — so a green run proves the harness itself. Place it in
(or the configured ).
patrol_test/test_directory遵循编写首个测试文档使用当前API:
https://patrol.leancode.co/documentation/write-your-first-test
确保首个测试独立运行——仅使用Flutter框架组件,不依赖应用或后端服务——这样测试通过即可证明测试环境本身正常。将测试文件放在目录下(或配置好的目录)。
patrol_test/test_directory3. Ignore the bundle and secrets
3. 忽略生成包与敏感信息
Gitignore (generated by Patrol) and (your
dart-defines, often secrets) per the Setup section:
https://patrol.leancode.co/documentation#setup
test_bundle.dart.patrol.env根据设置部分的指引,将(由Patrol生成)和(你的dart-defines,通常包含敏感信息)添加到.gitignore中:
https://patrol.leancode.co/documentation#setup
test_bundle.dart.patrol.env4. Run on an emulator
4. 在模拟器上运行测试
Boot an Android emulator and wait for boot to fully complete before running —
a test launched mid-boot fails. Then run the single test with . A
green run confirms the setup.
patrol test启动Android模拟器,等待完全启动后再运行测试——在启动过程中运行测试会失败。然后使用命令运行单个测试。测试通过即表示配置完成。
patrol testGotchas
常见陷阱
- cannot be resolved (Java) — set the
MainActivityMainActivityTest.javato the app'spackage.applicationId - Other errors (bundle build failures, hangs, flavor mismatches) — see the docs FAQ: https://patrol.leancode.co/documentation#faq
- 无法解析(Java)——将
MainActivity中的MainActivityTest.java设置为应用的package。applicationId - 其他错误(包构建失败、卡顿、构建变体不匹配)——请参考文档FAQ:https://patrol.leancode.co/documentation#faq
Next: Patrol MCP (optional)
下一步:Patrol MCP(可选)
Once the setup is green, mention to the user that Patrol MCP exists and can be
set up on request — it lets an AI agent run tests, capture screenshots, read the
native UI tree, and drive an interactive session. Let the user decide; if they
want it, follow the README: https://pub.dev/packages/patrol_mcp
配置完成并测试通过后,可告知用户Patrol MCP的存在,可按需配置——它支持AI Agent运行测试、捕获截图、读取原生UI树,并驱动交互式会话。由用户决定是否配置;若需要,请遵循README:https://pub.dev/packages/patrol_mcp