Espresso Barista

Post on 16-Jul-2015

249 views 4 download

Tags:

Transcript of Espresso Barista

ANDROID UI TESTINGShauvik Roy Choudhary

PhD candidate, Georgia Tech shauvik@gmail.com

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

TESTS

Unit Tests

Integration Tests

System Tests Functional Tests

Non-Functional Tests

ANDROID TESTING TOOLS

Image credits: BitBar

PROBLEM

Image credits: Google, GTAC talk

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

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

FLAKINESSUI Thread

Test Thread

Work in Queue

click

Motion down

Motion up

assert

FLAKINESSUI Thread

Test Thread

Work in Queue

click

Motion down

Motion up

assertsleep

FLAKINESSUI Thread

Test Thread

Work in Queue

click

Motion down

Motion up

assertsleep

TESTS

ESPRESSO: HOW IT WORKSUI Thread

Test Thread

Work in Queue

Test Case

Motion down

Motion upEspresso

action assert

Blocked

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)

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();

}

ESPRESSO METHODS

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

EXAMPLES

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

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

Find

Do Stuff

Check

onView(Matcher<View>)

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

perform(ViewAction)

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

check(ViewAssertion)

●  matches(...) ●  doesNotExist ●  myCustomAssertion

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

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

DEMO 1

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

DEMO 2

BARISTAEspresso Test Generation

Tests

TEST CLOUD