Source
Showing posts with label android testing. Show all posts
Showing posts with label android testing. Show all posts
Monday, November 12, 2018
Friday, November 9, 2018
Espresso dependencies
| /*Espresso testing */ | |
| androidTestImplementation 'com.android.support.test:runner:1.0.2' | |
| androidTestImplementation 'com.android.support.test:rules:1.0.2' | |
| androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' |
Full code of dependency:CODE
Toast message check
Code END
Labels:
android testing,
espresso
Saturday, November 3, 2018
how to create custome Matcher in Espresso android studio
Create a class name ErrorMatcher in androidTest folder.
public void testLoginMandatory()
{
onView(withId(R.id.email_sign_in_button)).perform(click());
onView(ErrorMatcher.withError(Matchers.
containsString("The field is required"))).check(matches(isDisplayed()));
}
public class ErrorMatcher {
@NonNull
public static Matcher withError(final Matcher stringMatcher) {
return new BoundedMatcher(TextView.class) {
@Override
public void describeTo(final Description description) {
description.appendText("error text: ");
stringMatcher.describeTo(description);
}
@Override
public boolean matchesSafely(final TextView textView) {
return stringMatcher.matches(textView.getError().toString());
}
};
}
}
# Maching logic is to match the subtext of the textview with only the error message.
#describeTo method only for debug.
# you can use this as your custom matcher in the test case as shown in below.
===================
@Test public void testLoginMandatory()
{
onView(withId(R.id.email_sign_in_button)).perform(click());
onView(ErrorMatcher.withError(Matchers.
containsString("The field is required"))).check(matches(isDisplayed()));
}
Source
Labels:
android testing,
espresso,
unit test
Subscribe to:
Posts (Atom)
