testing-setup
它能做什么
这个技能会检查 Android 项目目前的测试方式,并规划测试设置。它可以添加单元测试、UI 测试、截图测试和端到端测试所需的测试库与框架。适合希望建立可行测试策略的 Android 开发者。
适用场景
- ✓你的 Android 项目几乎没有测试,想建立测试设置的时候。
- ✓你想为 Compose 或 View 界面添加截图测试的时候。
- ✓你需要了解项目已在使用哪些测试库和模拟工具的时候。
技能链接
https://github.com/android/skills/blob/main/testing/testing-setup/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请帮我查看 Android 项目的测试设置,并添加单元测试和 Compose UI 测试所需的库。”
每周 5 个新技能,1 分钟读完。
工作原理
这个技能会读取你的版本目录和构建文件,找出依赖注入框架、测试框架、模拟工具和 UI 类型。然后添加项目中缺少的、适合的库和测试框架。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Step 1: Analyze the current testing setup
To understand the testing setup of an existing project, look for these dependencies in the libs.versions.toml file, or build files:
- Dependency Injection framework used. For example, Hilt, Koin, Anvil, or vanilla Dagger.
- Unit (local) testing framework this project uses. For example, JUnit4 or JUnit5.
- Mocking framework (if any) used for unit tests, and for instrumented and UI tests. For example, Mockito or Mockk.
- Robolectric. Identify which of these three uses apply:
- Used in unit tests to have fakes for platform entities
- To run behavior UI tests without a device or emulator. For example, used to run Espresso or Compose tests.
- To do screenshot testing with Roborazzi
- Is the app 100% Compose, Views or hybrid?
- Behavior UI tests:
- Compose Tests (
androidx.compose.ui:ui-test-*) - Espresso Tests for Views. Check for wrappers such as Kaspresso. Dependencies:
androidx.test.espresso:espresso-core,androidx.test:runner,androidx.test:rules.
- Compose Tests (
- Screenshot tests. Identify which of these types the project uses:
- Instrumented (device-based). For example, using Dropshots.
- Based on Robolectric, so they run locally. For example, using Roborazzi.
- Based on LayoutLib, so they run locally. For example, Paparazzi, or the Compose Preview Screenshot Testing tool.
- End to end tests (also known as Release Candidate tests) always run on device and use high-level frameworks such as UIAutomator, Appium, or Robotium.
- Generate a Markdown report with the analysis
Step 2: Set up Dependency Injection frameworks for testing
If there is no Dependency Injection framework, install one: if it's a multiplatform application, ask the user whether they want to install Koin, or kotlin-inject. If it's not multiplatform, install Hilt.
Install the testing dependencies (for example com.google.dagger:hilt-compiler
that should be applied with a kspAndroidTest configuration).
[!IMPORTANT] Important: Always consult the documentation of the applicable framework to learn about testing (for example: Hilt testing guide, Koin Instrumented tests).
For instrumented tests, create and configure (by adding
testInstrumentationRunner to the build gradle files) a new test runner and
apply the testing rules required by the framework (for example in Hilt, annotate
your test classes with @HiltAndroidTest and apply the HiltAndroidRule).
Other frameworks use other mechanisms, consult their documentation.
Step 3: Install frameworks
Unless otherwise specified, respect the current stack of testing frameworks.
If there are no testing frameworks, and the user didn't specify any preference, install the following:
JUnit4 for local and instrumented tests
JaCoCo for test coverage
For UI tests: if the project has views, Espresso. If it's fully Compose, use the Compose Testing APIs.
Robolectric to run UI Tests
Compose Preview Screenshot Testing tool for screenshot tests. Check the project's AGP version first, then pick the matching setup and follow it strictly:
- AGP 9.5.0-alpha03 or higher (recommended): configure an AGP test suite using
testOptions { screenshotTests.create(...) }, as described in Screenshot testing with test suites. - Lower AGP versions: use the legacy standalone plugin setup with
com.android.compose.screenshot, and tell the user it's deprecated. Don't upgrade AGP as part of setting up screenshot tests. Mention that test suites are available on 9.5.0-alpha03 or higher, and leave the upgrade as a separate decision.
Don't combine both setups in the same module. If the project already uses the standalone plugin and its AGP version supports test suites, offer to migrate it using the tasks and paths mapping table in Screenshot testing with test suites.
- AGP 9.5.0-alpha03 or higher (recommended): configure an AGP test suite using
Dropshots for device screenshot tests
If a mocking framework is necessary, install Mockk (
io.mockk:mockk). Do not install it unless it is clearly necessary.
If instrumented screenshot tests are requested, install Dropshots.
If end-to-end testing is requested, install
常见问题
它会编写我的实际测试用例吗?
这个技能只负责测试设置和测试框架,具体要测试哪些行为仍由你决定。
它支持哪些截图测试?
它支持基于设备的截图测试,以及基于 Robolectric 或 LayoutLib 的本地截图测试。
它能识别哪些依赖注入工具?
它能识别 Hilt、Koin、Anvil 和原生 Dagger 等框架。
详情
作者的原始描述
Analyze and create a testing strategy for Android apps - install testing libraries, set up test infrastructure, create harnesses for unit tests, UI tests, screenshot tests, and end-to-end tests.
repo: android/skills
热度
- GitHub 星标
- 10k
- 排名
- #11937
- 许可证
- Apache-2.0
- 更新时间
- 2026/10/29
评论
- …
同一仓库的更多技能
agp-9-upgrade
10k帮你的智能体把 Android 应用升级到 Android Gradle Plugin 9,并处理其中的破坏性变更。不适用于多平台项目。
camerax
10k帮你的智能体使用 CameraX 构建 Android 相机功能,包括视频录制、硬件控制以及 ML Kit 和 Media3 效果。
android-for-cars-parked-apps
10k帮你的智能体把 Android 视频、游戏或浏览器应用调整为可在 Android Auto 和 Android Automotive 上以停放应用形式运行。
appfunctions
10k帮你的智能体在 Android 应用中找到关键工作流,并把它们暴露为 AI 智能体和语音命令可以运行的 AppFunctions。