我正在使用espresso RecyclerViewAction测试我的回收站视图,但它没有通过测试。我的代码如下 -
@RunWith(AndroidJUnit4.class)
public class MainActivityUITest {
@Rule
public ActivityTestRule<MainActivity> mMainActivityTestRule = new ActivityTestRule<>(MainActivity.class);
@Test
public void recyclerViewTest_MovieSelectResult() {
onView(withId(R.id.rv_display_movies))
.perform(RecyclerViewActions.actionOnItemAtPosition(0, click()));
onView(withId(R.id.tv_title)).perform().check(matches(withText("Zootopia")));
}
}`
我已为包含回收站视图的活动初始化了ActivityTestRule,但仍然出现以下错误 -
android.support.test.espresso.PerformException: Error performing 'actionOnItemAtPosition performing ViewAction: single click on item at position: 0' on view 'with id: com.example.android.popularmoviestagetwo:id/rv_display_movies'.
at com.example.android.popularmoviestagetwo.MainActivityUITest.recyclerViewTest_MovieSelectResult(MainActivityUITest.java:30)
Caused by: java.lang.RuntimeException: Action will not be performed because the target view does not match one or more of the following constraints:
(is assignable from class: class android.support.v7.widget.RecyclerView and is displayed on the screen to the user)
Target view: "RecyclerView{id=2131296390, res-name=rv_display_movies, visibility=VISIBLE, width=1080, height=0, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=false, is-selected=false, layout-params=android.widget.FrameLayout$LayoutParams@9b64c52, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=0}"
答案 0 :(得分:1)
测试运行时未填充回收站视图。通过网络获取数据存在问题。这是一个网络问题。