Using Espresso for Fast and Reliable Feedback

Post on 05-Apr-2017

288 views 3 download

Transcript of Using Espresso for Fast and Reliable Feedback

Using Espresso for Fast and Reliable Feedback Web: perfectomobile.com Twitter: @perfectomobile

Using Espresso for Fast and Reliable Feedback

Embedding quality across the Android lifecycle

Web: perfectomobile.com Twitter: @perfectomobile

Using Espresso for Fast and Reliable Feedback Web: perfectomobile.com Twitter: @perfectomobile

● Session is being recorded

● Email once presentation is posted

● Questions and conversation○ Twitter: #justletmecode○ WebEx chat panel○ Q&A at the end of the webinar

Housekeeping

Paul BruceDeveloper Advocate

Perfecto

Using Espresso for Fast and Reliable Feedback Web: perfectomobile.com Twitter: @perfectomobile

What We’ll Cover

1. Introductions to Espresso testing framework○ The pattern and some code samples○ Comparing Espresso and Appium

2. Improving build verification in CI○ Testing types and schedules○ Espresso on real devices in Jenkins

3. Pros & Cons of DIY lab setup○ Common pitfalls and requirements for success

4. Accelerating the feedback loop

Using Espresso for Fast and Reliable Feedback Web: perfectomobile.com Twitter: @perfectomobile

Poll: Which UI testing technologies do you use?

● Espresso● Appium● Robotium● UI Automator● Other

Using Espresso for Fast and Reliable Feedback Web: perfectomobile.com Twitter: @perfectomobile

Introductions to the Espresso test framework

IUsing Espresso for Fast and Reliable Feedback

Embedding quality across the Android lifecycle

Using Espresso for Fast and Reliable Feedback Web: perfectomobile.com Twitter: @perfectomobile

Automated UI Testing for Android apps

● Creates folder for tests (androidTests)

● Adds Espresso libraries as dependencies

Using Espresso for Fast and Reliable Feedback Web: perfectomobile.com Twitter: @perfectomobile

On the surface, a fluent UI testing pattern

onData(ObjectMatcher).DataOptions.perform(ViewAction).check(ViewAssertion)

Find ItAct on ItCheck It

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

Using Espresso for Fast and Reliable Feedback Web: perfectomobile.com Twitter: @perfectomobile

Espresso syntax in a nutshellFind

onView(withId(R.id.bill_value))

onView(allOf(withId(R.id.bill_value),isDisplayed()

))

// see ViewMatchers.

Act

.perform(replaceText(“25.44”))

.perform(click(), typeText(“...”)

)

.perform(pressBackButton())

.perform(swipeUp())

// see ViewActions.

Check

.check(matches(isDisplayed()))

.check(matches(not(isDisplayed())

))

.check(doesNotExist())

.check(matches(withText(“...”)))

// see ViewAssertions.

Using Espresso for Fast and Reliable Feedback Web: perfectomobile.com Twitter: @perfectomobile

Espresso in Android Studio

Using Espresso for Fast and Reliable Feedback Web: perfectomobile.com Twitter: @perfectomobile

How ADB andinstrumentationwork together

Using Espresso for Fast and Reliable Feedback Web: perfectomobile.com Twitter: @perfectomobile

How does the alternative (Appium) work?

Using Espresso for Fast and Reliable Feedback Web: perfectomobile.com Twitter: @perfectomobile

Pros/cons on both sidesEspresso/XCTest WebDriver...

Instrumented Black-box

Code+ XPath+

Ecosystem IndependentUpgrades

Execution

Object Locators

N YCross-platform

Depends+ Depends-Stability

bit.ly/oss-test-choices

Using Espresso for Fast and Reliable Feedback Web: perfectomobile.com Twitter: @perfectomobile

Espresso avoids sleep() creep

Using Espresso for Fast and Reliable Feedback Web: perfectomobile.com Twitter: @perfectomobile

Espresso avoids XPath delta breakage

Strings tell your compiler NOTHING!!!

No refactoring support

Can you write them properly...yes! Do you?

None of these things apply to compilable statements (i.e. R…).

Using Espresso for Fast and Reliable Feedback Web: perfectomobile.com Twitter: @perfectomobile

More Espresso getting started resources:

● Intro to Espresso and Spoonbit.ly/2kN4DAZ

● Vogella - Espresso Tutorialbit.ly/2l0y6lY

● Watch everything from Chiu Ki Chan on YouTube

● Tweet / email me with questions! @paulsbruce me@paulsbruce.io

Using Espresso for Fast and Reliable Feedback Web: perfectomobile.com Twitter: @perfectomobile

Improving build verification in CI

2Using Espresso for Fast and Reliable Feedback

Embedding quality across the Android lifecycle

Using Espresso for Fast and Reliable Feedback Web: perfectomobile.com Twitter: @perfectomobile

Feedback loops across the pipeline

Using Espresso for Fast and Reliable Feedback Web: perfectomobile.com Twitter: @perfectomobile

Complete feedback at the right times

Using Espresso for Fast and Reliable Feedback Web: perfectomobile.com Twitter: @perfectomobile

Local Build Commit → Build Full / Nightly

Unit / New UI Integration / Smoke Full Regression

Fake Real Real

Static Mocks SandboxAPI

Tests

Hardware

A simple recipe for fast and complete feedback

< 2min < 20min < 2hr

Espresso in Jenkins

Using Espresso for Fast and Reliable Feedback Web: perfectomobile.com Twitter: @perfectomobile

Pros & cons of DIY lab setup

3Using Espresso for Fast and Reliable Feedback

Embedding quality across the Android lifecycle

Using Espresso for Fast and Reliable Feedback Web: perfectomobile.com Twitter: @perfectomobile

Devices: local or cloud?

Local Build Merge → Build Full / Nightly

✓ ! ✘

! ✘ ✘

✓ ✓ ✓Cloud Lab

Emulator

Local Lab

Using Espresso for Fast and Reliable Feedback Web: perfectomobile.com Twitter: @perfectomobile

Less hunting, more coding

● How many devices per developer?● In sync with the market?● Spares, adapters?● Storage/hosting/power costs?● Monitoring?● Security?

● High-volume automated testing● Big data from CI● Results retention & collaboration

Using Espresso for Fast and Reliable Feedback Web: perfectomobile.com Twitter: @perfectomobile

Using Espresso for Fast and Reliable Feedback Web: perfectomobile.com Twitter: @perfectomobile

Using Espresso for Fast and Reliable Feedback Web: perfectomobile.com Twitter: @perfectomobile

Complete quality across the entire lifecycle

Using Espresso for Fast and Reliable Feedback Web: perfectomobile.com Twitter: @perfectomobile

Accelerating the feedback loop

4Using Espresso for Fast and Reliable Feedback

Embedding quality across the Android lifecycle

Using Espresso for Fast and Reliable Feedback Web: perfectomobile.com Twitter: @perfectomobile

Build verification, smoke tests

x5 per day * 4 critical platforms

Regression &end-to-end testing

nightly * 16 platforms + conditions

fast & complete feedback

Parallel testing requires a reliable, scalable lab

Using Espresso for Fast and Reliable Feedback Web: perfectomobile.com Twitter: @perfectomobile

Fast feedback means a lab that fits into your workflow

bit.ly/perfecto-slack

Using Espresso for Fast and Reliable Feedback Web: perfectomobile.com Twitter: @perfectomobile

Using Espresso for Fast and Reliable Feedback Web: perfectomobile.com Twitter: @perfectomobile

Using Espresso for Fast and Reliable Feedback Web: perfectomobile.com Twitter: @perfectomobile

Using Espresso for Fast and Reliable Feedback Web: perfectomobile.com Twitter: @perfectomobile

A complete view of build quality

Using Espresso for Fast and Reliable Feedback Web: perfectomobile.com Twitter: @perfectomobile

What We’ve Covered Today

1. Introductions to Espresso testing framework○ The pattern and some code samples○ Comparing Espresso and Appium

2. Improving build verification in CI○ Testing types and schedules○ Espresso on real devices in Jenkins

3. Pros & Cons of DIY lab setup○ Common pitfalls and requirements for success

4. Accelerating the feedback loop

4 Ways to Speed Up Your Mobile/Web App Daily Grind Web: perfectomobile.com Twitter: @perfectomobile

Q&A .