Robolectric usage
Activity
@RunWith(RobolectricTestRunner::class) // or ParameterizedRobolectricTestRunner for parameterized test
@GraphicsMode(GraphicsMode.Mode.NATIVE)
class SnapActivityTest {
@get:Rule
val robolectricScreenshotRule =
robolectricActivityScenarioForActivityRule(
config = ActivityConfigItem(
systemLocale = "en",
uiMode = UiMode.NIGHT,
theme = R.style.Custom_Theme,
orientation = Orientation.PORTRAIT,
fontSize = FontSize.NORMAL,
displaySize = DisplaySize.NORMAL,
fontWeight = FontWeight.BOLD,
),
deviceScreen = DeviceScreen.Phone.PIXEL_4A,
)
@Config(sdk = [30]) // Do not use qualifiers if using `DeviceScreen` in the Rule
@Test
fun snapActivity() {
robolectricScreenshotRule
.rootView
.captureRoboImage("path/MyActivity.png")
}
}Fragment
Android View
Jetpack Compose
Multiple Devices & Configs combined
Last updated