亲爱的堆栈溢出社区,我们如何使用Espresso测试PreferenceFragment的android设置活动?
我们如何使用咖啡onView和在包含PreferenceFragment这样的设置活动执行: http://developer.android.com/guide/topics/ui/settings.html#Fragment
亲爱的堆栈溢出社区,我们如何使用Espresso测试PreferenceFragment的android设置活动?
我们如何使用咖啡onView和在包含PreferenceFragment这样的设置活动执行: http://developer.android.com/guide/topics/ui/settings.html#Fragment
的偏好在一个列表,所以你必须查询具体的偏好是这样的:
// Check if is displayed
onData(allOf(is(instanceOf(Preference.class)), withKey("prefkey"))).check(matches(isDisplayed()));
// Perform click
onData(allOf(is(instanceOf(Preference.class)), withKey("prefkey"))).onChildView(withClassName(is(Switch.class.getName()))).perform(click());
我发现这篇文章有帮助:http://www.winters.nz/2015/05/espresso-for-android-hints-properties.html
请尝试以下逻辑
// Check if it is displayed
onData(PreferenceMatchers.withKey(context.getResources().getString(R.string.prefkey))).check(matches(isDisplayed()));