Skip to content

Write & Run Screenshot Tests

akshay-at-yml edited this page Aug 25, 2022 · 16 revisions

Shot and Showkase

Writing shot tests and using showkase in test classes are explained in the individual sections. This section will briefly show how to combine them with the below two appraoches.

Showkase Generated Tests.

In this approach, test class will implement ShowkaseScreenshotTest interface.
The test class must be abstract, and must be annotated with the @ShowkaseScreenshot as shown below. Showkase will autogenerate tests for each of the Previews / Colors / Typography available in the shoskase browser.

onScreenshot of ShowkaseScreenshotTest will provide a bitmap for each of the component in the showkase browser, which is then recorded or compared using Shot's compareScreenshot method.

@ShowkaseScreenshot(rootShowkaseClass = DesignModule::class)
abstract class DesignTests : ShowkaseScreenshotTest, ScreenshotTest {
    @get:Rule
    override val composeTestRule: ComposeContentTestRule = createComposeRule()

    override fun onScreenshot(
        id: String,
        name: String,
        group: String,
        styleName: String?,
        screenshotType: ShowkaseScreenshotType,
        screenshotBitmap: Bitmap
    ) {
        compareScreenshot(screenshotBitmap, "${group}_${name}")
    }
}

Using Showkase Metadata

Paparazzi and Showkase

Clone this wiki locally