About This Series of Articles: Testing Android Applications - Part 1
About This Series of Articles: Testing Android Applications - Part 1
Unit tests and testing are parts of each developer’s life and they are important parts of development.
Developers usually concentrate on unit tests which help them ensure that future changes will not break
the system and let other people do tests and stress tests of applications to reveal bugs, which we as
developers simply cannot see.
Unit Testing
There are basically three levels of tests/unit-test you can use in your application:
1. Unit testing of logic which does not depend on android at all. This is similar to every usual unit
testing. Running tests directly from Eclipse requires some configuration changes which we will cover
later.
2. Unit testing of business logic which depends on Android but does not depend on Android
application elements and UI. This logic does not require activity to be running with complete context
and it can be tested in isolation from UI. This tests usually require something from context (e.g.
resources, configuration, logger, some native classes)
3. Unit/functional testing of Android application elements. These tests are fully instantiated
activities, services, content providers and applications.
Via instrumentation it is possible to send keyboard and touch events to the activities and check
response in UI. It is possible to test lifecycle of a service and to test databases changes made by
content provider.
To be able to test layers of the application in isolation using and fully use previous three levels. It is
useful to follow these guidelines during design and development phases of your Android application:
Image on the left shows “Run Configuration” dialog with Android library not deleted and image on the
right shows configuration of build path. It is sometimes even possible to unit test classes which depend
on classes from android.jar by deleting JUnit classes in the jar file. But once tested classes require
something from android runtime, you get exceptions.
<instrumentation
android:name=„android.test.InstrumentationTestRunner“
android:targetPackage=„eu.inmite.prj.aclient“
android:label=„Tests for Small Applacation“ />
where:
1. android:name is name of the test runner class – use android.test.InstrumentationTestRunner as
default
2. android:targetPackage is application package you want to instrument
3. android:label is name of the test which appears under Instrumentation in Dev Tools application
Monkey
Does everything seem to be too complicated for you? Do you wonder if there is simple way how to test
Android application? The answer is UI/Application Exerciser Monkey tool available in Android SDK.
Monkey is quite fast way for testing of UI. Just be warned that monkey does not like real devices yet.
There is bug which causes that monkey is killed by Android whenever it tries to send a notification key to
the real T-Mobile G1 device. Now our clever monkey likes to work without bugs with the emulator only.