Changing the font scale in a test
Testify allows you to change the current Activity scaling factor for fonts, relative to the base density scaling. This allows you to simulate the impact of a user modifying the default font size on their device, such as tiny, large or huge.
note
Similar to changing the Locale
, you are required to implement TestifyResourcesOverride
when configuring fontScale
. See Changing the Locale in a test.
See Change text & display settings
Example Test:
- ScreenshotTestRule
- ScreenshotScenarioRule
class MainActivityScreenshotTest {
@get:Rule var rule = ScreenshotRule(MainActivity::class.java)
@ScreenshotInstrumentation
@TestifyLayout(R.layout.view_client_details)
@Test
fun testHugeFontScale() {
rule
.configure {
fontScale = 2.0f
}
.assertSame()
}
}
class MainActivityScreenshotTest {
@get:Rule val rule = ScreenshotScenarioRule()
@ScreenshotInstrumentation
@TestifyLayout(R.layout.view_client_details)
@Test
fun testHugeFontScale() {
overrideResourceConfiguration<MainActivity>(fontScale = 2.0f)
launchActivity<MainActivity>().use { scenario ->
rule
.withScenario(scenario)
.assertSame()
}
}
}