General / Android testing talk I gave at the October Mobile Dev NJ Meetup. The talk covers types of testing, what parts of a program or app should be tested, and what libraries and strategies to use with Android to begin testing.
it. Ensure that the UI acts independent of the core (API). We accomplish this by testing all components of the View or UI. Once completed it is a good idea to always stress test your UI to catch edge cases.
test the User Interface the Robolectric library in conjunction with Junit are used. This library allows tests to be run using the JVM instead of an Android device.
API testing should be completely separate from UI or View testing. Test all public methods except standard setters and getters. Typically JUnit and Mockito are used to test. (Junit testing can be done through the user of CI)
application, through the use random events. First launch your application on an Android device and then run : $ adb shell monkey -p your.package.name -v #ofRandomEvents to get Exerciser Monkey Started
this program from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice # Connects to the current device, returning a MonkeyDevice object device = MonkeyRunner.waitForConnection() # Installs the Android package. Notice that this method returns a boolean, so you can test # to see if the installation worked. device.installPackage(‘path to apk’) # sets a variable with the package's internal name package = ‘com.ekamp.testing' # sets a variable with the name of an Activity in the package activity = ‘MainActivity' # sets the name of the component to start runComponent = package + '/' + activity # Runs the component device.startActivity(component=runComponent) # Presses the Menu button device.press('KEYCODE_MENU', MonkeyDevice.DOWN_AND_UP) # Takes a screenshot result = device.takeSnapshot() # Writes the screenshot to a file result.writeToFile('myproject/sampleShot.png','png')