gpt4 book ai didi

android - 如何调整 Robolectric 测试的屏幕密度?

转载 作者:行者123 更新时间:2023-11-29 01:12:41 24 4
gpt4 key购买 nike

我目前正在我的应用程序中测试 fragment 方法,该方法对其运行设备的 DisplayMetrics 设置敏感。如何在 RobolectricTestRunner 的 Robolectric 测试中调整 DisplayMetrics(如果可能,请提供示例)?

这是我希望能够控制屏幕的 DisplayMetrics 的简单测试的要点。

    @Test
public void whenMyFramentMethod_willWorkForDensity() {

...

startFragment(fragment);

//Results of this method will vary with different screen sizes.
Assert.assertEquals(200, fragment.fetchAWidth());
}

最佳答案

您现在应该使用@Config 注释来设置环境:

@Config(qualifiers = "xhdpi")

关于android - 如何调整 Robolectric 测试的屏幕密度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41832829/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com