मैं परीक्षण करना चाहता हूं कि कोई संपादन टेक्स्ट फ़ील्ड में कोई त्रुटि है (editText.setError ("खाली नहीं हो सकता है!") के साथ सेट करें)।एंड्रॉइड पर एस्प्रेसो के साथ एडिटटेक्स्ट त्रुटियों का परीक्षण
मैं नए AndroidStudio 2.2 की सुविधा के साथ एक एस्प्रेसो परीक्षण का मामला, एस्प्रेसो परीक्षण रिकॉर्ड करने के लिए बनाया है। तो कोड बहुत अधिक ऑटो जनरेटेड है। लेकिन अभी के लिए यह केवल जांचता है कि संपादन टेक्स्ट प्रदर्शित होता है या नहीं।
@RunWith(AndroidJUnit4.class)
public class CreateNoteActivityTitleCannotBeBlank {
@Rule
public ActivityTestRule<CreateNoteActivity> mActivityTestRule = new ActivityTestRule<>(CreateNoteActivity.class);
@Test
public void createNoteActivityTitleCannotBeBlank() {
ViewInteraction floatingActionButton = onView(
allOf(withId(R.id.fab_add_note),
withParent(allOf(withId(R.id.activity_create_note),
withParent(withId(android.R.id.content)))),
isDisplayed()));
floatingActionButton.perform(click());
ViewInteraction editText = onView(
allOf(withId(R.id.tiet_note_title),
childAtPosition(
childAtPosition(
withId(R.id.til_title),
0),
0),
isDisplayed()));
editText.check(matches(isDisplayed()));
}
private static Matcher<View> childAtPosition(
final Matcher<View> parentMatcher, final int position) {
return new TypeSafeMatcher<View>() {
@Override
public void describeTo(Description description) {
description.appendText("Child at position " + position + " in parent ");
parentMatcher.describeTo(description);
}
@Override
public boolean matchesSafely(View view) {
ViewParent parent = view.getParent();
return parent instanceof ViewGroup && parentMatcher.matches(parent)
&& view.equals(((ViewGroup) parent).getChildAt(position));
}
};
}
}
क्या त्रुटि प्रदर्शित होने पर परीक्षण करने का कोई तरीका है?
करने के लिए बदल adnotation [एंड्रॉयड एस्प्रेसो की @Nullable – Genehme
संभावित डुप्लिकेट जोड़ने का प्रयास करें। TextInputLayout में ErrorText की जांच कैसे करें] (http://stackoverflow.com/questions/34285782/android-espresso-how-to-check-errortext-in-textinputlayout) –