-
Notifications
You must be signed in to change notification settings - Fork 2
Paparazzi
Its an Android library which can render application UI without the need of android emulator or a physical device. It will also allows to capture snapshots of the rendered UI, and perform screenshot testing.
Paparazzi tests are not instrumentation tests as emulators or physical devices are not required. Paparazzi APIs are only accessible in the unit test folder.
In the Unit test class, create paparazzi instance. paparazzi.snapshot{}
will allow to call any composable functions and takes a snapshot of it.
@get:Rule
val paparazzi = Paparazzi(
maxPercentDifference = PERCENT_DIFFERENCE,
// device configurations can be specifies
deviceConfig = PIXEL_4_XL,
)
....
@Test
fun testMethod() {
paparazzi.snapshot {
//Call any composable methods to be tested
// Can write various combinations of theme, layout directions using CompositionLocalProvider
}
}
Paparazzi instance will allow to create Device configurations on which the tests can be run. It has a set of predefined device configurations like PIXEL_4_XL,
NEXUS_5_LAND
etc.
If you want to change the device later while running tests, use below API.
paparazzi.unsafeUpdateConfig(// Pass device config here)
You can set the tolerance by setting maxPercentDifference
when creating the Paparazzi instance. Values will range from 0.1 to 1.0
Example : If maxPercentDifference = 0.1
⇒ The tests will be passed until the change exceed 0.1
To record the screenshots
./gradlew <module-name>:recordPaparazziDebug
To verify the screenshots against golden values,
./gradlew <module-name>:verifyPaparazziDebug
💡 Recommended to clean the module before recording or verifying ./gradlew <module-name>:clean
Add the following plugin dependency in the root project.
dependencies {
classpath 'app.cash.paparazzi:paparazzi-gradle-plugin:1.0.0'
}
Apply the plugin in the module where Paparazzi tests should be written.
apply plugin: 'app.cash.paparazzi'