0

I use Espresso library in my project. In tutorial and samples have examples how to test adapter and view. But I have custom adapter and custom specific view. My view:

<?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>

My test:

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

It's work. But I don't now what data have view. Haw can I open Spinner and click for item?

4

1 回答 1

3

我找到答案。找到并单击微调器

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

为 Spinner 获取数据

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

检查数据

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

比点击它查看

ViewMatchers?.hasSibling(ViewMatchers?.withText(listCity.get(0).getName())))).perform(ViewActions?.click());
于 2014-01-27T10:49:53.933 回答