对于ins,如下面的示例,我希望首先设置监听器并使用espresso,因此如何实现toMatcher
@Test
public void testSpinner2() throws Exception {
r.launchActivity(null);
Spinner sp = (Spinner) r.getActivity().findViewById(R.id.spinner);
sp.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//do smth
}
});
onView(toMatcher(sp));
}
答案 0 :(得分:0)
I guess following code can work:
public static Matcher<View> toMatcher(final View v) {
return new TypeSafeMatcher<View>() {
@Override
protected boolean matchesSafely(View item) {
return item == v;
}
@Override
public void describeTo(Description description) {
description.appendText(v.toString());
}
};
}