安卓.浓咖啡.如何在自定义适配器中测试自定义视图



我在项目中使用浓缩咖啡库。在教程和样本中,有示例如何测试适配器和查看。但是我有自定义适配器和自定义特定视图。我的观点:

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
    android:id="@+id/tvCity"
    style="@style/Widget.TextView.OnlyOneLine"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="@dimen/ab_city_spinner_inner_padding"
    android:text="Test"
    android:textColor="@color/ab_city_spinner_city_text"
    android:textSize="@dimen/ab_city_spinner_city_text_size" />
<TextView
    android:id="@+id/tvRegion"
    style="@style/Widget.TextView.OnlyOneLine"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="@dimen/ab_city_spinner_inner_padding"
    android:text="Test"
    android:textColor="@color/ab_city_spinner_region_text"
    android:textSize="@dimen/ab_city_spinner_region_text_size" /></LinearLayout>

我的测试:

@SmallTest
public void testChangeCity()
{
    onView(withId(R.id.spAB)).perform(ViewActions.click());
    onView(allOf(withText("City1"), hasSibling(withText("Test")))).perform(ViewActions.click());
}

这是工作。但是我现在没有哪些数据视图。我可以打开旋转器并单击项目吗?

我找到答案。查找并单击Spinner

Espresso.onView(ViewMatchers?.withId(R.id.spAB)).perform(ViewActions?.click());

获取旋转器的数据

List<City> listCity = getActivity().getCityList();

检查数据

Preconditions.checkNotNull(listCity, "No have any city");

单击它查看

ViewMatchers?.hasSibling(ViewMatchers?.withText(listCity.get(0).getName())))).perform(ViewActions?.click());

最新更新