27
TESTING SUCKS NOVEMBER 2011 NICHOLAS FITZROY-DALE

Testing Sucks, But It Doesn't Have To

  • Upload
    apkudo

  • View
    1.251

  • Download
    2

Embed Size (px)

DESCRIPTION

Writing an app for Android takes a lot of work. One of the greatest pains developers suffer from is the testing process, which many do badly or not at all. Why? Testing sucks - but it's a necessary evil.In this class, you'll learn about test methods available to developers today, in particular Monkey, the user interface testing tool. You'll learn why Monkey is such an effective tool, and how to use it to test your own apps. You'll also learn about the limitations of Monkey, especially when it comes to making sure your app runs on any Android device. Finally, you'll learn about Apkudo, a testing solution that lets developers see how their apps install, execute, and perform on every (yes, every) Android device, assuring interoperability and customer satisfaction.Testing doesn't have to suck. We'll show you why.

Citation preview

Page 1: Testing Sucks, But It Doesn't Have To

TESTING SUCKS

NOVEMBER 2011

NICHOLAS FITZROY-DALE

Page 2: Testing Sucks, But It Doesn't Have To

TESTING IS LIKE FLOSSING

Page 3: Testing Sucks, But It Doesn't Have To

©  2011  -­‐  CONFIDENTIAL  

©  2011  -­‐  CONFIDENTIAL  

©  2011  -­‐  CONFIDENTIAL  

©  2011  -­‐  CONFIDENTIAL  

©  2011  -­‐  CONFIDENTIAL  

©  2011  -­‐  CONFIDENTIAL  

3 ©2011 Apkudo Inc. www.apkudo.com

61% CRASHES

54% WON’T INSTALL

Page 4: Testing Sucks, But It Doesn't Have To

99%

4 ©2011 Apkudo Inc. www.apkudo.com

“I TEST MY APP!”

Page 5: Testing Sucks, But It Doesn't Have To

99%

5 ©2011 Apkudo Inc. www.apkudo.com

“I TEST MY APP!”

O RLY?

85% MANUAL  

Page 6: Testing Sucks, But It Doesn't Have To

6 ©2011 apkudo, inc. Confidential www.apkudo.com

OH NOES

Page 7: Testing Sucks, But It Doesn't Have To

7 ©2011 apkudo, inc. Confidential www.apkudo.com

AD HOC TESTING

Sucks Keeping up with device versions Testing across various devices

AUTOMATED TESTING Tedious JUnit, Robotium Test plan

Page 8: Testing Sucks, But It Doesn't Have To

8 ©2011 apkudo, inc. Confidential www.apkudo.com

MONKEY! A good start. Simulates inputs. Completely automated.

Page 9: Testing Sucks, But It Doesn't Have To

9 ©2011 apkudo, inc. Confidential www.apkudo.com

MONKEY OVERVIEW

   Ac$vity  Manager      Start  /  stop  ac:vi:es      Get  list  of  running  ac:vi:es  

   Window  Manager      Send  touch  and  key  events        to  foreground  app  

   Package  Manager      Install  and  uninstall  packages      Get  list  of  package  ac:vi:es  

ocean-­‐flisch.deviantart.com  

Page 10: Testing Sucks, But It Doesn't Have To

10 ©2011 apkudo, inc. Confidential www.apkudo.com

MONKEY OVERVIEW

   Ac$vity  Manager      setActivityController()

   Window  Manager      inject*Event()

   Package  Manager   queryIntentActivities()

Page 11: Testing Sucks, But It Doesn't Have To

11 ©2011 apkudo, inc. Confidential www.apkudo.com

MONKEY SEE MONKEY DO •  Monkey injects “events” - what is an event?

– KeyEvent: Hardware buttons and keyboard – MotionEvent: X, Y, and touches – FlipEvent, NetworkEvent, PowerEvent (mostly

legacy)

Page 12: Testing Sucks, But It Doesn't Have To

Security  

•  Monkey uses standard Android permissions... that no user apps can use!

public static final String SET_ACTIVITY_WATCHER Since: API Level 1 Allows an application to watch and control how activities are started globally in the system. Only for is in debugging (usually the monkey command).

public static final String INJECT_EVENTS Since: API Level 1 Allows an application to inject user events (keys, touch, trackball) into the event stream and deliver them to ANY window. Without this permission, you can only deliver events to windows in your own process. Very few applications should need to use this permission.

12 ©2011 apkudo, inc. Confidential www.apkudo.com

SECURITY

Page 13: Testing Sucks, But It Doesn't Have To

Monkey  vs  Monkey  Runner  

•  Monkey is for randomized testing, and runs on the device

•  Monkey Runner is for scripting your own tests, and runs on a laptop / desktop

•  In fact, Monkey Runner uses Monkey internally

MONKEY VS MONKEY RUNNER

Page 14: Testing Sucks, But It Doesn't Have To

Monkey  on  Angry  Birds  

adb shell monkey –v -p com.rovio.angrybirds -s 39 --throttle 10 --pct-touch 100 5000

adb shell monkey -p com.rovio.angrybirds 500014 ©2011 apkudo, inc. Confidential www.apkudo.com

THE BIRDS, THEY ARE ANGRY!

Page 15: Testing Sucks, But It Doesn't Have To

What  can  Monkey  find?  

•  Key and motion events •  Crash information if applicable, as traceback

15 ©2011 apkudo, inc. Confidential www.apkudo.com

MONKEY RESULTS :AllowPackage:  com.rovio.angrybirds  :IncludeCategory:  android.intent.category.LAUNCHER  :IncludeCategory:  android.intent.category.MONKEY  :Switch:  #Intent;ac:on=android.intent.ac:on.MAIN;category=android.intent.category.LAUNCHER;launchFlags=0x10000000;component=com.rovio.angrybirds/com.rovio.ka3d.App;end        //  Allowing  start  of  Intent  {  act=android.intent.ac:on.MAIN  cat=[android.intent.category.LAUNCHER]  cmp=com.rovio.angrybirds/com.rovio.ka3d.App  }  in  package  com.rovio.angrybirds  :Sending  Pointer  ACTION_DOWN  x=554.0  y=357.0  :Sending  Pointer  ACTION_UP  x=558.0  y=350.0        //  Rejec:ng  start  of  Intent  {  act=android.intent.ac:on.CALL_BUTTON  cmp=com.android.contacts/.DialtactsAc:vity  }  in  package  com.android.contacts  :Sending  Pointer  ACTION_DOWN  x=696.0  y=280.0  :Sending  Pointer  ACTION_UP  x=709.0  y=271.0  :Sending  Pointer  ACTION_MOVE  x=-­‐1.0  y=1.0  :Sending  Pointer  ACTION_DOWN  x=348.0  y=10.0  

Page 16: Testing Sucks, But It Doesn't Have To

What  can  Monkey  find?  

•  Weird UI sequences – Press button 2 before button 1

•  Unexpected inputs – E.G. keyboard input during a Toast

•  User-interface race conditions •  Activity life-cycle errors

16 ©2011 apkudo, inc. Confidential www.apkudo.com

WHAT CAN MONKEY FIND?

Page 17: Testing Sucks, But It Doesn't Have To

Weird  UI  sequences  

•  Monkey presses UI controls in an unexpected way

•  Example: Comic Rack: selecting “Options” immediately after application start

•  Resolution: Always check preconditions in UI callback functions

17 ©2011 apkudo, inc. Confidential www.apkudo.com

WEIRD UI SEQUENCES

Page 18: Testing Sucks, But It Doesn't Have To

Unexpected  inputs  

•  Monkey simulates keypresses that the application doesn’t expect

•  Example: multiple keypresses on the same button

•  Resolution: Again, be paranoid when entering UI callback functions

18 ©2011 apkudo, inc. Confidential www.apkudo.com

UNEXPECTED INPUTS

Page 19: Testing Sucks, But It Doesn't Have To

Race  condi:ons  

•  Monkey can press UI elements very quickly, triggering race conditions

•  Example: I Heart Radio: PlayerController not initialized

•  Resolution: limit use of threads. When they are necessary, perform appropriate locking.

•  Same applies to networking.

19 ©2011 apkudo, inc. Confidential www.apkudo.com

RACE CONDITIONS

Page 20: Testing Sucks, But It Doesn't Have To

Ac:vity  life-­‐cycle  errors  

•  Monkey performs unexpected activity life-cycle actions

•  Example: Shazam: Unable to pause activity •  Resolution: Become tiresomely familiar

with the Android activity life cycle.

ACTIVITY LIFE CYCLE ERRORS

Page 21: Testing Sucks, But It Doesn't Have To

Mul:-­‐device  Monkey  

•  Monkey is really good at testing across multiple devices:

•  Correct Market permissions – appropriate-architecture native code, eg armv7

•  Unexpected hardware properties •  “Weird” hardware failures

MULTI-DEVICE MONKEY

Page 22: Testing Sucks, But It Doesn't Have To

Mul:-­‐device  Monkey  

•  OpenGL ES version and features •  Dependencies on system libraries •  Incorrect or missing minSdkVersion

CORRECT MARKET FILTERS

Page 23: Testing Sucks, But It Doesn't Have To

Unexpected  hardware  proper:es  

•  The device has an unexpected hardware feature (e.g. a strange screen resolution)

•  Examples: RDefense Free, Zombie Killer •  Best resolution: Test on multiple devices

UNEXPECTED HARDWARE PROPERTIES

Page 24: Testing Sucks, But It Doesn't Have To

Weird  hardware  failures  

•  Not all devices “just work” •  Example: PaperCamera doesn’t handle

RuntimeError from takePicture() •  Resolution: Test on multiple devices. Be

wary of Java unchecked errors.

24 ©2011 apkudo, inc. Confidential www.apkudo.com

WEIRD HARDWRE FAILURES

Page 25: Testing Sucks, But It Doesn't Have To

Limita:ons  

•  False positives – “Impossible” sequences of actions / speeds

•  Very limited testing strategy – What if most of your app is hidden behind a login

screen? •  Some Android pain points not covered

– E.G. screen rotation, layout issues

25 ©2011 apkudo, inc. Confidential www.apkudo.com

MONKEY LIMITATIONS

Page 26: Testing Sucks, But It Doesn't Have To

Apkudo  

•  “See your app run on every Android device” – Monkey test on 289 phones and tablets – Free – Private beta right now: email

[email protected] if interested

26 ©2011 apkudo, inc. Confidential www.apkudo.com

AND APKUDO

Page 27: Testing Sucks, But It Doesn't Have To

Thank you. NFD@ .COM