Upload
shauvik-roy-choudhary
View
127
Download
2
Tags:
Embed Size (px)
Citation preview
WRITING AUTOMATION TESTSShauvik Roy Choudhary
Instructor, Georgia Tech [email protected]
WHY AUTOMATE TESTS?
Software
Manual Testing
PLATFORMS
Web Tester
Mobile Tester
LollipopAndroid 5.0
4
HOW TO AUTOMATE?
HOW
Infrastructure
Tool Support
WHAT
Parts of your App
INFRASTRUCTURE
• Unit TestsxUnit for different programming languages
• UI TestsSelenium/WebDriver for Web Apps Appium for Mobile (iOS, Android)Espresso for Android
IDEAL TESTING PYRAMIDby Mike Cohn
ICE-CREAM CONE
HOUR GLASS
source: just-about.net
TESTING DIAMOND
Source: toddlittleweb.com
CHRISTMAS TREE
source: just-about.net
UI TESTS CLOSEST TO
END-USER TESTING
UI TESTING ISSUES
• FRAGILITY
• SPEED
• FLAKINESS
1. FRAGILE TESTS
REDUCING FRAGILITY
• Use durable selectors
• IDs over XPath
• Relative XPaths over Absolute XPaths
• Other durable labels (class, content-desc..)
2. SLOW TESTS
MAKING TESTS FAST
• Don’t use Sleeps
• If absolutely necessary, sleep while polling
• Replace slow resources with stubs
3. FLAKY TESTS
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
REDUCING FLAKINESS
• Have a hermetic test environment
Source: googletesting.blogspot.com
ANDROID UI TESTING
ANDROID TESTING TOOLS
Image credits: BitBar
ESPRESSO: HOW IT WORKSUI Thread
Test Thread
Work in Queue
Test Case
Motion down
Motion upEspresso
action assert
Blocked
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
Tests
TEST CLOUD
THANKS!