abgeschottete realität - testen im emulator, mobile testing days 2014, berlin

Post on 07-Jul-2015

264 Views

Category:

Technology

1 Downloads

Preview:

Click to see full reader

DESCRIPTION

Mobile Apps leben nicht in einer isolierten Welt, sie interagieren mit anderen Apps, mit Services sowie internen und externen Datenquellen. Auch der Nutzer hat hier Einfluss: er wechselt in Realität schnell zwischen Apps, er nimmt Anrufe entgegen während die App läuft. Wenn es zum Testen kommt, stellt uns dies vor Herausforderungen, denn hier brauchen wir isolierte Zustände. Nur so können die Tests reproduzierbare Ergebnisse liefern. Und doch wollen wir die App realitätsnah testen. Wie testet man aber eine App mit Webservices? Wie entkoppelt man diesen, wie testet man Fehlerzuständige die in der Kommunikation passieren können? Wie simuliert man GPS u.ä.? Diese Session versucht Best Practices hierzu zu vermitteln. Es werden sowohl SDK Bordmittel als auch externe Tools vorgestellt, die uns das Testen von Apps in diesen komplexen Fällen erleichtern.

TRANSCRIPT

Danny Preussler | Groupon

Abgeschottete Realität

about me and testing

• 2014, Java/Eclipse Magazin

• "Android-apps testen mit Espresso“• Android Engineer, Groupon

about me and testing

• 2013, DroidCon Berlin

• “Unit testing mit Robolectric“• Lead Engineer Android, eBay Kleinanzeigen

about me and testing

• 2008, Blackberry Developer Conference,

Santa Clara

• “Unit testing with Blackberry“

• Team Lead Mobile, Cortado

about me and testing

• 2004?, OOP München

• Besuch eines Vortrags

von James Whitaker,

der Testgedanken bis heute prägt

• Developer, Thinprint

about me and testing

• 2001, Diplomarbeit

• UI Testing a protocol implementation

between Alcatel and Lucent

• Student developer, Alcatel

Our mobile app is available in 43 countries

Groupon’s vibrant mobile marketplace connects

consumers with their local economy

Sources: Internal Data; iTunes ranking for US stores available here -https://itunes.apple.com/WebObjects/MZStore.woa/wa/viewFeature?id=500873243&mt=8&v0=www-itunes25Bcountdown-appstore

Nearly 70 million people worldwide have downloaded our mobile app to date; 9 million in Q4 2013.

One of the 25 most downloaded free apps of all time

Nearly 50% of our global transactions completed on a mobile device in December 2013

Abgeschottet?

• App isolieren

• Äußere Faktoren reduzieren

• Reproduzierbarkeit erhöhen

Broken Blackberry by Matthew Hurst, CC BY 2.0, http://www.flickr.com/photos/skewgee/3160670483

Android emulator

Android emulator

• Teil des SDK

• Stellt alle Nexus Geräte zur Verfügung

• Custom Versionen erstellbar

Android emulator

• Erstellung über UI oder Commandlineandroid create avd -n my_android1.5

• Dateien (*.avd, *.ini) liegen in $USERHOME/.android/avd

• Perfekt für Jenkins und Skriptingandroid move avd / android delete avd -n

<name>

Android emulator

• Performance schlecht

• Verbesserung durch:

– Enable „use host GPU“

– Use Intel Builds

– Install Intel Hardware Accelerationhttps://software.intel.com/en-us/android/articles/installation-instructions-for-intel-

hardware-accelerated-execution-manager-mac-os-x

Genymotion

Genymotion

• Unschlagbare Performance

• Vordefinierte VMs aus Cloud laden

• Kostenfrei nur für privat

My

gra

ndpas

hom

eby

florianric, C

C B

Y 2

.0, https://w

ww

.flic

kr.

com

/photo

s/f

lorianric/7

263382550

adb

• Android debug bridge

• Funktioniert mit jedem Android Gerät!

adb

• Geht auch wenn Gerät gelockt:

adb

adb devices

adb install <apk-file>

adb uninstall <your-package>

adb

adb reboot

adb start-server / kill-server

adb logcat

adb

adb push <path> <device-path>

adb pull <path-on-device>

adb

adb shell screencap -p |

perl -pe 's/\x0D\x0A/\x0A/g' >

~/Desktop/screenshot.png

adb shell

Adb provides a Unix shell that you can

use to run a variety of commands on an

emulator or connected device.

(http://developer.android.com/tools/help/adb.html#shellcommands)

adb

• Send „monkey“ events:

adb shell monkey

-p your.package.name

-v 500

Squirre

lm

onkey

with

ice

cre

am

by

Ta

mbako

the

Jaguar, C

C B

Y 2

.0, h

ttps://w

ww

.flickr.c

om

/photo

s/ta

mbako/1

1481700755

SharedPreferences

• Meistgenutzer Persistence-Mechanismus

SharedPreferences preferences =

PreferenceManager.getDefaultSharedPreferences(context);

...preferences.getString(key, default);

SharedPreferences

• Zugriff:

adb shell cat /data/data/com.your-

package/shared_prefs/com.your-

package_preferences.xml

adb shell ls /data/data/com.your-

package/shared_prefs

SharedPreferences

• Beispiel:

<?xml version='1.0' encoding='utf-8' standalone='yes‘?>

<map>

<string name=“key">value</string>

</map>

SharedPreferences

• Reproduzierbarkeit der Test

durch back/restore

• Beispiel:adb pull

/data/data/eu.esa.spaceappcamp.enviq/shared_prefs/eu.esa

.spaceappcamp.enviq_preferences.xml

Databases

• Komplexere Daten werden meist in

SQLite Datenbanken gespeichert

• Backup-Restore-Pattern:

/data/data/com.your-

package/databases/

Databases

• Example:adb pull

/data/data/com.groupon.redemption/databases/red

emption.db

• Open with SQLite Manager für Firefoxhttps://addons.mozilla.org/en-

US/firefox/addon/sqlite-manager/

Accounts

• Account-Daten sollten

über Android Account

Manager hinterlegt

werden

Accounts

Liegen unter: /data/system/users/0/accounts.db

(evtl unterschiedlich je Android Version)

telnet

telnet localhost 5554

Trying 127.0.0.1...

Connected to localhost.

Escape character is '^]'.

Android Console: type 'help'

for a list of commands

OK

Amiga 1000 connected to an Apple IIgs-hosted BBS via telnet by Blake

Patterson, CC BY 2.0, https://www.flickr.com/photos/blakespot/12421642963

telnet

• Works with android emulators

• Does not work with phones

• Does not work with Genymotion

Amiga 1000 connected to an Apple IIgs-hosted BBS via telnet by Blake

Patterson, CC BY 2.0, https://www.flickr.com/photos/blakespot/12421642963

telnetevent simulate hardware events

geo Geo-location commands

gsm GSM related commands

cdma CDMA related commands

kill kill the emulator instance

network manage network settings

power power related commands

redir manage port redirections

sms SMS related commands

avd control virtual device execution

window manage emulator window

qemu QEMU-specific commands

sensor manage emulator sensors

telnetevent simulate hardware events

geo Geo-location commands

gsm GSM related commands

cdma CDMA related commands

kill kill the emulator instance

network manage network settings

power power related commands

redir manage port redirections

sms SMS related commands

avd control virtual device execution

window manage emulator window

qemu QEMU-specific commands

sensor manage emulator sensors

telnetevent simulate hardware events

geo Geo-location commands

gsm GSM related commands

cdma CDMA related commands

kill kill the emulator instance

network manage network settings

power power related commands

redir manage port redirections

sms SMS related commands

avd control virtual device execution

window manage emulator window

qemu QEMU-specific commands

sensor manage emulator sensors

telnet

• Einkommende Anrufe simulieren:

gsm call 1234567

gsm cancel 1234567

• Wozu?

Wie reagiert die Anwendung?

Kann sie sich korrekt wiederherstellen?

telnetevent simulate hardware events

geo Geo-location commands

gsm GSM related commands

cdma CDMA related commands

kill kill the emulator instance

network manage network settings

power power related commands

redir manage port redirections

sms SMS related commands

avd control virtual device execution

window manage emulator window

qemu QEMU-specific commands

sensor manage emulator sensors

telnet> help network

allows you to manage the settings related to the network

data connection of the

emulated device.

available sub-commands:

network status dump network status

network speed change network speed

network delay change network latency

network capture dump network packets to file

telnet

• Geschwindigkeit drosseln:network speed 14.4 80

telnetevent simulate hardware events

geo Geo-location commands

gsm GSM related commands

cdma CDMA related commands

kill kill the emulator instance

network manage network settings

power power related commands

redir manage port redirections

sms SMS related commands

avd control virtual device execution

window manage emulator window

qemu QEMU-specific commands

sensor manage emulator sensors

telnet

geo fix <longitude> <latitude>

GPS

• Google Play services nicht auf

Emulatoren verfügbar

• Google? ;-)

Genymotion Shellandroid informations related to Android system

included in Genymotion distribution

battery actions and informations related to battery

sensor

devices generic actions related to virtual devices

(listing, selection, ...)

gps actions and informations related to Global

Positioning System sensor

pause make a pause (useful for automatic tests)

rotation actions related to the rotation of virtual

device

version display version number of running Genyshell

Web Services

• Mock daten?

– Einfach bei Entwicklernahen

Testframeworks:

Android Instrumentation, Robotium,

Espresso

– Ideal beim Einsatz von Dependency-

Injection wie Dagger, RoboGuice

Web Services

• Mock daten?

– „Schwer-unmöglich“ bei Black-Box oder

Remote-Framworks wie UIAutomator,

RoboRemote, Selenium...

Web Services

• Skripte zum Manipulieren des Backends

-> Komplexität, Externe Abhängigkeit!

• Besser: Proxy:

– Charles

www.charlesproxy.com

– Odo:

https://github.com/groupon

Odo-ed

Response Override

• Return fixed response content

• Return fixed response code

• Add delays

Response Override cont.

• Add/remove request headers

• Change content

• Change response code

Response Override cont.

• Do sequences of all those

• Supports Plugins for custom responses

i.e. makeDealSoldOut

Request Override

• Add/remove request headers

• Custom request – add/change parameters

• Change the target

i.e. send production request to staging/test

Developer-Options

How do we test?

• RoboRemote

• github.com/groupon/robo-remote

• UIAutomator + Robotium

• works from remote

• Espresso

• Odo

Follow us

https://engineering.groupon.com/

Michael Burton, Roboguice

Carlos Sessa, 50 Android hacks

David van der Bokke, RoboRemote

David Willson, Odo

….

Get the demo app:

https://play.google.com/store/apps/details?id=eu.esa.spaceappcamp.enviq

Thank you

top related