Cross-Library usage
AndroidUiTestingUtils provides out-of-the-box support to write screenshot tests that can run across libraries for Composables and Android Views
To configure cross-library screenshot tests, you need to follow the steps in this section.
Once done, write your tests like this:
Define a ScreenshotTestRule with the default configuration, which can be overriden in your tests
fun defaultCrossLibraryScreenshotTestRule(
config: ScreenshotConfigForComposable,
): ScreenshotTestRule =
CrossLibraryScreenshotTestRule(config)
// Optional: Define special configurations for each library you're using
.configure(
ShotConfig(bitmapCaptureMethod = PixelCopy())
).configure(
DropshotsConfig(
bitmapCaptureMethod = PixelCopy(),
resultValidator = ThresholdValidator(0.15f)
)
).configure(
AndroidTestifyConfig(bitmapCaptureMethod = PixelCopy())
).configure(
PaparazziConfig(deviceConfig = DeviceConfig.NEXUS_4)
).configure(
RoborazziConfig(
filePath = File(userTestFilePath()).path,
deviceScreen = DeviceScreen.Phone.NEXUS_4,
)
)Write a screenshot test
or a parameterized screenshot test
You must define a testInstrumentationRunner in build.gradle of type androidx.test.runner.AndroidJUnitRunner for Parameterized Cross-Library screenshot tests to work. For instance, com.karumi.shot.ShotTestRunnerif using Shot.
Last updated