我目前正在我的应用程序中测试一个 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/