08 September, 2012

Stress Testing Android Application Activity Start/Stop

One of the things I find before delivering Android applications is the impact of starting and stopping the application in a rapid manner. It's common that key stroke and touch handlers get invoked before all the necessary resources have been created, or after they have been released. Starting an application, followed by hitting the back button or home button can often result in calls to your application handlers or scheduled behavior after onStop() has been invoked. I find the following script assists in stress testing this form of behavior:

#!/bin/bash


for t in {0..5}; do
  for i in {0..10}; do
    adb -s emulator-5554 shell am start -a android.intent.action.MYAPPNAME -n com.abc.myappname/com.abc.myappname.MyAppName
    sleep $t
    adb shell input keyevent 3
    sleep 5
  done
done

The above script will repeatedly start the application, wait X seconds, then post the 'home' keyevent. If my app passes this test, and a series of monkey tests I'm pretty confident the users won't experience unexpected crashes. Cheers.

No comments: