親愛的堆棧溢出社區,我們如何使用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()));