85
MOVE FAST AND FIX TESTS Shauvik Roy Choudhary @shauvik http://shauvik.com GOING FROM MANUAL TO AUTOMATED:

From Manual to Automated Tests - STAC 2015

Embed Size (px)

Citation preview

Page 1: From Manual to Automated Tests - STAC 2015

MOVE FAST AND FIX TESTS

Shauvik Roy Choudhary @shauvik http://shauvik.com

GOING FROM MANUAL TO AUTOMATED:

Page 2: From Manual to Automated Tests - STAC 2015
Page 3: From Manual to Automated Tests - STAC 2015
Page 4: From Manual to Automated Tests - STAC 2015

MOVE FAST AND FIX TESTS

Shauvik Roy Choudhary @shauvik http://shauvik.com

GOING FROM MANUAL TO AUTOMATED:

Page 5: From Manual to Automated Tests - STAC 2015

MOVE FAST AND FIX TESTS

Shauvik Roy Choudhary @shauvik http://shauvik.com

GOING FROM MANUAL TO AUTOMATED:

Checks

Page 6: From Manual to Automated Tests - STAC 2015

ABOUT ME• PhD Thesis:

Cross-platform Testing & Maintenance of Web & Mobile Apps

• Industry: Google, Yahoo!, FullStory, Fujitsu Labs, IBM Research, HSBC, Goldman Sachs

• Entrepreneurship: Georgia Tech TI:GER program, VentureLab, ATDC, TechSquare Labs

Shauvik Roy Choudhary PhD, Georgia Tech

Founder, CheckDroid

Page 7: From Manual to Automated Tests - STAC 2015

OUTLINE• MOTIVATION: Why Automate ?

• MOVE FAST: How to Automate Quickly?

• FIX TESTS: How to Resolve Automation Issues?

• SCENARIO: Android UI Testing

• DISCUSSION

Page 8: From Manual to Automated Tests - STAC 2015

WHY AUTOMATE TESTS?

Software

Manual Testing

Page 9: From Manual to Automated Tests - STAC 2015

WHY AUTOMATE TESTS?

Software

Manual Testing

Page 10: From Manual to Automated Tests - STAC 2015

WHY AUTOMATE TESTS?

Software

Manual Testing

Page 11: From Manual to Automated Tests - STAC 2015

WHY AUTOMATE TESTS?

Software

Manual Testing

Page 12: From Manual to Automated Tests - STAC 2015

WHY AUTOMATE TESTS?

Software

Manual Testing

Page 13: From Manual to Automated Tests - STAC 2015

PLATFORMS

Web Tester

Page 14: From Manual to Automated Tests - STAC 2015

PLATFORMS

Web Tester

Page 15: From Manual to Automated Tests - STAC 2015

PLATFORMS

Web Tester

Page 16: From Manual to Automated Tests - STAC 2015

PLATFORMS

Web Tester

Page 17: From Manual to Automated Tests - STAC 2015

PLATFORMS

Web Tester

Page 18: From Manual to Automated Tests - STAC 2015

PLATFORMS

Web Tester

Page 19: From Manual to Automated Tests - STAC 2015

PLATFORMS

Web Tester

Page 20: From Manual to Automated Tests - STAC 2015

PLATFORMS

Web Tester

Page 21: From Manual to Automated Tests - STAC 2015

Mobile Tester

LollipopAndroid 5.0

9

Page 22: From Manual to Automated Tests - STAC 2015

HOW TO AUTOMATE?

Page 23: From Manual to Automated Tests - STAC 2015

HOW TO AUTOMATE?

WHAT

Parts of your App

Page 24: From Manual to Automated Tests - STAC 2015

HOW TO AUTOMATE?

HOW

Infrastructure

Tool Support

WHAT

Parts of your App

Page 25: From Manual to Automated Tests - STAC 2015

WHAT: TO TEST

• Functional Tests Positive and negative scenarios

• Non-Functional Tests Performance, Security, Compatibility…

• Previous Issues (identified Manually) Never to occur in Regressions

Page 26: From Manual to Automated Tests - STAC 2015

HOW: INFRASTRUCTURE

• Unit TestsxUnit for different programming languages

• UI TestsSelenium/WebDriver for Web Apps Appium for Mobile (iOS, Android)Espresso for Android

Page 27: From Manual to Automated Tests - STAC 2015

IDEAL TESTING PYRAMIDby Mike Cohn

Page 28: From Manual to Automated Tests - STAC 2015

ICE-CREAM CONE

Page 29: From Manual to Automated Tests - STAC 2015

HOUR GLASS

source: just-about.net

Page 30: From Manual to Automated Tests - STAC 2015

TESTING DIAMOND

Source: toddlittleweb.com

Page 31: From Manual to Automated Tests - STAC 2015

CHRISTMAS TREE

source: just-about.net

Page 32: From Manual to Automated Tests - STAC 2015

UI TESTS CLOSEST TO

END-USER TESTING

Page 33: From Manual to Automated Tests - STAC 2015

MOVE FASTHow to automate quickly?

Page 34: From Manual to Automated Tests - STAC 2015

RELIABLE INFRASTRUCTURE

Page 35: From Manual to Automated Tests - STAC 2015

VISUAL TEST RECORDING

Page 36: From Manual to Automated Tests - STAC 2015

FIX TESTSHow to fix broken tests?

Page 37: From Manual to Automated Tests - STAC 2015

UI TESTING ISSUES

Page 38: From Manual to Automated Tests - STAC 2015

UI TESTING ISSUES

• FRAGILITY

Page 39: From Manual to Automated Tests - STAC 2015

UI TESTING ISSUES

• FRAGILITY

• SPEED

Page 40: From Manual to Automated Tests - STAC 2015

UI TESTING ISSUES

• FRAGILITY

• SPEED

• FLAKINESS

Page 41: From Manual to Automated Tests - STAC 2015

1. FRAGILE TESTS

Page 42: From Manual to Automated Tests - STAC 2015

REDUCING FRAGILITY

• Use durable selectors

• IDs over XPath

• Relative XPaths over Absolute XPaths

• Other durable labels (class, content-desc..)

Page 43: From Manual to Automated Tests - STAC 2015

2. SLOW TESTS

Page 44: From Manual to Automated Tests - STAC 2015

MAKING TESTS FAST

• Don’t use Sleeps

• If absolutely necessary, sleep while polling

• Replace slow resources with stubs

Page 45: From Manual to Automated Tests - STAC 2015

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

Page 46: From Manual to Automated Tests - STAC 2015

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

Page 47: From Manual to Automated Tests - STAC 2015

FLAKINESSUI Thread

Test Thread

Work in Queue

Page 48: From Manual to Automated Tests - STAC 2015

FLAKINESSUI Thread

Test Thread

Work in Queue

click

Page 49: From Manual to Automated Tests - STAC 2015

FLAKINESSUI Thread

Test Thread

Work in Queue

click

Motion down

Motion up

Page 50: From Manual to Automated Tests - STAC 2015

FLAKINESSUI Thread

Test Thread

Work in Queue

click

Motion down

Motion up

assert

Page 51: From Manual to Automated Tests - STAC 2015

FLAKINESSUI Thread

Test Thread

Work in Queue

click

Motion down

Motion up

assert

Page 52: From Manual to Automated Tests - STAC 2015

FLAKINESSUI Thread

Test Thread

Work in Queue

click

Motion down

Motion up

assertsleep

Page 53: From Manual to Automated Tests - STAC 2015

FLAKINESSUI Thread

Test Thread

Work in Queue

click

Motion down

Motion up

assertsleep

Page 54: From Manual to Automated Tests - STAC 2015

TESTS

Page 55: From Manual to Automated Tests - STAC 2015

3. FLAKY TESTS

Image credits: Google, GTAC talk

Page 56: From Manual to Automated Tests - STAC 2015

REDUCING FLAKINESS• Have a hermetic test environment

Source: googletesting.blogspot.com

Page 57: From Manual to Automated Tests - STAC 2015

REDUCING FLAKINESS• Have a hermetic test environment

Source: googletesting.blogspot.com

Page 58: From Manual to Automated Tests - STAC 2015

FIX TESTS

Page 59: From Manual to Automated Tests - STAC 2015

1. FRAGILE TESTS

FIX TESTS

Page 60: From Manual to Automated Tests - STAC 2015

1. FRAGILE TESTS

2. SLOW TESTS

FIX TESTS

Page 61: From Manual to Automated Tests - STAC 2015

1. FRAGILE TESTS

2. SLOW TESTS

3. FLAKY TESTS

Image credits: Google, GTAC talk

FIX TESTS

Page 62: From Manual to Automated Tests - STAC 2015

ANDROID UI TESTING

Page 63: From Manual to Automated Tests - STAC 2015

MOBILE TESTING PYRAMID

Source: Daniel Knott, AdventuresInQAAuthor: Hand-On Mobile App Testing

Page 64: From Manual to Automated Tests - STAC 2015

ANDROID TESTING TOOLS

Image credits: BitBar

Page 65: From Manual to Automated Tests - STAC 2015

ESPRESSO: HOW IT WORKSUI Thread

Test Thread

Work in Queue

Test Case

Motion down

Motion upEspresso

action assert

Blocked

Page 66: From Manual to Automated Tests - STAC 2015

ESPRESSO METHODS

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

Page 67: From Manual to Automated Tests - STAC 2015

EXAMPLES

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

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

Page 68: From Manual to Automated Tests - STAC 2015

EXAMPLES

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

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

Find

Page 69: From Manual to Automated Tests - STAC 2015

EXAMPLES

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

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

Find

Do Stuff

Page 70: From Manual to Automated Tests - STAC 2015

EXAMPLES

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

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

Find

Do Stuff

Check

Page 71: From Manual to Automated Tests - STAC 2015

onView(Matcher<View>)

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

Page 72: From Manual to Automated Tests - STAC 2015

perform(ViewAction)

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

Page 73: From Manual to Automated Tests - STAC 2015

check(ViewAssertion)

●  matches(...) ●  doesNotExist ●  myCustomAssertion

Page 74: From Manual to Automated Tests - STAC 2015

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 75: From Manual to Automated Tests - STAC 2015

BARISTAEspresso Test Generation

http://checkdroid.com/barista

Page 76: From Manual to Automated Tests - STAC 2015

DEMO

Page 77: From Manual to Automated Tests - STAC 2015

Tests

Page 78: From Manual to Automated Tests - STAC 2015

TEST CLOUD

Page 79: From Manual to Automated Tests - STAC 2015
Page 80: From Manual to Automated Tests - STAC 2015

WHY AUTOMATE TESTS?

Software

Manual Testing

Page 81: From Manual to Automated Tests - STAC 2015

WHY AUTOMATE TESTS?

Software

Manual Testing

MOVE FASTHow to automate quickly?

Page 82: From Manual to Automated Tests - STAC 2015

WHY AUTOMATE TESTS?

Software

Manual Testing

MOVE FASTHow to automate quickly?

1. FRAGILE TESTS

2. SLOW TESTS

3. FLAKY TESTS

Image credits: Google, GTAC talk

FIX TESTS

Page 83: From Manual to Automated Tests - STAC 2015

WHY AUTOMATE TESTS?

Software

Manual Testing

MOVE FASTHow to automate quickly?

1. FRAGILE TESTS

2. SLOW TESTS

3. FLAKY TESTS

Image credits: Google, GTAC talk

FIX TESTSANDROID UI TESTING

Page 84: From Manual to Automated Tests - STAC 2015

DISCUSSIONAre you currently automating tests?

What are some challenges that you see?

Page 85: From Manual to Automated Tests - STAC 2015

THANKS!Shauvik Roy Choudhary

@shauvik http://shauvik.com