Espresso Barista

24
ANDROID UI TESTING Shauvik Roy Choudhary PhD candidate, Georgia Tech [email protected] Team: Mattia Fazzini, Eduardo Noronha Advisor: Alessandro (Alex) Orso

Transcript of Espresso Barista

Page 1: Espresso Barista

ANDROID UI TESTINGShauvik Roy Choudhary

PhD candidate, Georgia Tech [email protected]

Team: Mattia Fazzini, Eduardo Noronha Advisor : Alessandro (Alex) Orso

Page 2: Espresso Barista

TESTS

Unit Tests

Integration Tests

System Tests Functional Tests

Non-Functional Tests

Page 3: Espresso Barista

ANDROID TESTING TOOLS

Image credits: BitBar

Page 4: Espresso Barista

PROBLEM

Image credits: Google, GTAC talk

Page 5: Espresso Barista

doSomething()Thread.sleep(1000) checkSomething()

Page 6: Espresso Barista

doSomething()do{ Thread.sleep(1000) }while(!loaded) checkSomething()

Page 7: Espresso Barista

FLAKINESSUI Thread

Test Thread

Work in Queue

click

Motion down

Motion up

assert

Page 8: Espresso Barista

FLAKINESSUI Thread

Test Thread

Work in Queue

click

Motion down

Motion up

assertsleep

Page 9: Espresso Barista

FLAKINESSUI Thread

Test Thread

Work in Queue

click

Motion down

Motion up

assertsleep

Page 10: Espresso Barista

TESTS

Page 11: Espresso Barista

ESPRESSO: HOW IT WORKSUI Thread

Test Thread

Work in Queue

Test Case

Motion down

Motion upEspresso

action assert

Blocked

Page 12: Espresso Barista

IDLING RESOURCES

public interface IdlingResource {

public String getName();

public boolean isIdleNow();

public void registerIdleTransitionCallback(ResourceCallback cb);

public interface ResourceCallback {

public void onTransitionToIdle();

}

}

Espresso.registerIdlingResource(MyIdlingResource)

Page 13: Espresso Barista

CHECKING INTENTS

public interface IntentSpy {

public List<ResolvedIntent> getLatestRecordedIntents();

public void record(Intent intent);

public ActivityResult getActivityResultForIntent(Intent intent);

public boolean allowIntentToProceed(Intent intent);

public void reset();

}

Page 14: Espresso Barista

ESPRESSO METHODS

onView(Matcher) .perform(ViewAction) .check(ViewAssertion)

Page 15: Espresso Barista

EXAMPLES

onView(withId(R.id.greeting)) .perform(click());

onView(withText("Hello Steve!")) .check(matches(isDisplayed()));

Find

Do Stuff

Check

Page 16: Espresso Barista

onView(Matcher<View>)

●  withId ●  withText ●  withContentDescription ●  isDisplayed ●  hasFocus ●  hasSibling ●  ... ●  mySpecialMatcher

Page 17: Espresso Barista

perform(ViewAction)

●  click ●  longClick ●  doubleClick ●  typeText ●  scrollTo ●  ... ●  myCustomAction

Page 18: Espresso Barista

check(ViewAssertion)

●  matches(...) ●  doesNotExist ●  myCustomAssertion

Page 19: Espresso Barista

HIERARCHYwithParent(Matcher)withChild(Matcher)hasDescendant(Matcher)isDescendantOfA(Matcher)hasSibling(Matcher)isRoot()

UI PROPERTIESisDisplayed()isCompletelyDisplayed()isEnabled()hasFocus()isClickable()isChecked()isNotChecked()withEffectiveVisibility(…)isSelected()

ROOT MATCHERSisFocusable()isTouchable()isDialog()withDecorView(…)isPlatformPopup()

COMMON HAMCRESTMATCHERSallOf(Matchers)anyOf(Matchers)is(...)not(...)endsWith(String)startsWith(String)

SEE ALSOPreference matchersCursor matchers

USER PROPERTIESwithId(…)withText(…)withTagKey(…)withTagValue(…)hasContentDescription(…)withContentDescription(…)withHint(…)withSpinnerText(…)hasLinks()hasEllipsizedText()hasMultilineText()

INPUTsupportsInputMethods(…)hasImeAction(…)

CLASSisAssignableFrom(…)withClassName(…)

MatchersCLICK/PRESSclick()doubleClick()longClick()pressBack()pressImeActionButton()pressKey([int/EspressoKey])pressMenuKey()closeSoftKeyboard()openLink(…)

GESTURESscrollTo()swipeLeft()swipeRight()swipeUp()swipeDown()

TEXTclearText()typeText(String)typeTextIntoFocusedView(String)replaceText(String)

POSITION ASSERTIONSisLeftOf(Matcher)isRightOf(Matcher)isLeftAlignedWith(Matcher)isRightAlignedWith(Matcher)isAbove(Matcher)isBelow(Matcher)isBottomAlignedWith(Matcher)isTopAlignedWith(Matcher)

LAYOUT ASSERTIONSnoEllipsizedText(Matcher)noMultilineButtons()noOverlaps([Matcher])

View Actions

matches(Matcher)doesNotExist()selectedDescendantsMatch(…)

View Assertions

onView(Matcher) .perform(ViewAction) .check(ViewAssertion)

CHEAT SHEET

2.0

Page 20: Espresso Barista

https://github.com/ shauvik/espresso-examples

DEMO 1

Page 21: Espresso Barista

https://github.com/googlesamples/android-testing

DEMO 2

Page 22: Espresso Barista

BARISTAEspresso Test Generation

Page 23: Espresso Barista

Tests

Page 24: Espresso Barista

TEST CLOUD