一键导入
build-grid-screenshot-tests
A skill for building instrumented tests in Remote Compose using GridScreenshotUI.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
A skill for building instrumented tests in Remote Compose using GridScreenshotUI.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
This skill should be used when the user asks about "running iOS tests", "iOS instrumented tests", "how to run ios tests", "launch specific ios test", "add new ios instrumented test" and these tests are located in the "compose/ui/ui/src/uikitInstrumentedTest" directory.
A skill for building instrumented screenshot tests in Remote Compose using RemoteComposeScreenshotTestRule.
This skill should be used when the user asks to "update Kotlin version", "upgrade Kotlin", "change Kotlin to X.Y.Z", or mentions updating the Kotlin compiler version in the project.
| name | build_grid_screenshot_tests |
| description | A skill for building instrumented tests in Remote Compose using GridScreenshotUI. |
[!IMPORTANT] AI INSTRUCTION: Do not assume you should use
GridScreenshotUIfor all tests in this directory. If the user asks you to write a screenshot test, you MUST first explicitly ask them: "Would you like me to use theGridScreenshotUIutility for this test?" Proceed with using this skill only if they confirm.
This skill provides guidelines for building screenshot tests using GridScreenshotUI in the @compose/remote/remote-creation-compose project.
GridScreenshotUI is a utility class designed to lay out multiple small remote UI components in a grid. This is particularly useful for screenshot testing as it allows you to capture many variations of a component (e.g., different alignments, modifiers, or arrangements) in a single screenshot, making tests more efficient and easier to compare visually.
GridScreenshotUITest Class Setup:
Create a test class annotated with @MediumTest, @SdkSuppress(minSdkVersion = 35, maxSdkVersion = 35), and @RunWith(AndroidJUnit4::class).
Add the Screenshot Rule:
Define a RemoteComposeScreenshotTestRule explicitly specifying the module directory and matcher.
@get:Rule
val composeTestRule: RemoteComposeScreenshotTestRule by lazy {
RemoteComposeScreenshotTestRule(
moduleDirectory = SCREENSHOT_GOLDEN_DIRECTORY,
matcher = MSSIMMatcher(threshold = 0.999),
)
}
Instantiate GridScreenshotUI:
Create an instance of GridScreenshotUI in your test class.
private val gridScreenshotUI = GridScreenshotUI()
Define your UI variations:
Create a method or variable that provides a list of Pair<String, @RemoteComposable @Composable () -> Unit>. The string is the label for the variation, and the lambda is the actual Compose UI content.
You can use the .toInput() extension functions defined in GridScreenshotUI.Companion to easily convert a list of composables into the required pair format if you don't want to specify labels manually.
Write the Test:
Use composeTestRule.runScreenshotTest and call gridScreenshotUI.GridContent(...) with your list of variations.
@Test
fun exampleGridTest() =
composeTestRule.runScreenshotTest {
gridScreenshotUI.GridContent(getLayoutAlignmentUIs())
}
GridScreenshotUI.Companion.DefaultContainerSize to maintain consistent container dimensions across tests.layoutDirection = LayoutDirection.Rtl to GridContent.
gridScreenshotUI.GridContent(
getLayoutAlignmentUIs(),
layoutDirection = LayoutDirection.Rtl,
)
Pair items if you have a combinatorial explosion of parameters (like trying out all combinations of Arrangements and Alignments through sequence).
private fun getLayoutAlignmentUIs(): List<Pair<String, @RemoteComposable @Composable () -> Unit>> =
sequence {
for (alignment in alignments) {
for (arrangement in arrangements) {
yield(
"${alignment.propertyName()} ${arrangement.propertyName()}" to
@RemoteComposable @Composable {
RemoteRow(
modifier = RemoteModifier.size(DefaultContainerSize),
horizontalArrangement = arrangement,
verticalAlignment = alignment,
) {
// Your content here
}
}
)
}
}
}.toList()