This is how we set up our android testing environment. It is a process which makes maintaining android app quality incredibly simple. We start off by using maven-android-plugin to “mavenize” our android project.
There are a few advantages here. One big advantage of this is using maven’s convention over configuration. Another big plus is that it ties your project together nicely so you can have testing project and a main project. Likewise anyone starting off using your app should be able to quickly get all dependencies which can be a nightmare at times. It also ties the project nicely together for Jenkins/Hudson which you will see later. Here is a great overview of Maven & Android and how to set it up by Sonatype http://www.sonatype.com/books/mvnref-book/reference/android-dev.html.
From here we need to set up how to test. We basically concentrate on two types of tests here. Functional UI tests which we use Robotium (you say click here, expect this text). And then we use Android JUnit tests as described by the official android developer guide for testing things like variables during the app life-cycle. These are all contained in the testing project which with the help of maven will run during the test life-cycle. We then use the projects parent pom (which ties everything together – test project & main) and use it within a Jenkins/Hudson instance. Jenkins/Hudson (I wont get into the specifics of both but for the purpose of our testing they are virtually the same) is awesome. We use our maven parent pom.xml and set up a new maven project in Jenkins/Hudson with the maven goals “clean install site.” If your not familiar with Maven, this is basically telling your Jenkins/Hudson server to use this projects settings to test and build your android app.
Here are a few plugins to Jenkins/Hudson which makes this testing environment even greater. PMD has some android specific rulesl that are worth their weight in gold, so we plug that into our continuous integration server (Jenkins/Hudson). Still with us? Good. We use findbugs as android is written in java and findbugs rocks. Then we use the android emulator plugin which is where the magic happens. Note: All three are installed in Hudson/Jenkins using “Manage Hudson” -> “Manage Plugins” -> “Available” tab. From here, we see the big benefit of writing all those unit tests we described before (Robotium & JUnit). Using android emulator plugin, you can test against a wide variety of android devices very easily and painlessly. These tests drastically simplify the task of testing. From here, we set it to poll our SVN every 30 minutes for changes. So from here you can easily maintain your app against all android OS’s, device displays, and locale.
Just check your code in as normal and monitor your builds for any issues (your build will fail if a unit test fails on a device and you can quickly check its log). I hope this helps anyone wanting to improve the quality of their android tests.