Tuesday, September 13, 2011

Android, Ant, Emma, Robotium

We started a new android project at work today.  Since there isn't any legacy development we wanted to get it started right, with a continuous integration environment so we wanted to automate the build and testing as an ant task.  I was unable to find anything on the android developer site outlining the process to set this up, so I turned to the internet.  Nothing on the first couple pages of google results had a complete recipe so I figured I ought to share the solution we used.

Requirements
  • Eclipse
  • Android SDK
  • ADT
  • Ant
  • Robotium jar
Create Android Application
  • File -> New -> Other...
  • Open Android -> Select Android Project -> Click Next
  • Set Project name, Android <Version>, Package name (The rest should be filled out with reasonable defaults)
  • Click Finish
Add Ant Script
  • Open terminal to project directory
% $ANDROID_HOME/tools/android update project --path .
Updated local.properties
Added file ./build.xml
Updated file ./proguard.cfg

Create Android Test Application
  • File -> New -> Other...
  • Open Android -> Select Android Test Project -> Click Next
  • Set An existing Android project (The rest should be filled in with reasonable defaults)
Add Ant Script
  • Open terminal to test project directory
% $ANDROID_HOME/android update test-project -m ../BigMeanRobot --path .
Resolved location of main project to: /Users/daya/src/BigMeanRobot/BigMeanRobot
Updated default.properties
Updated local.properties
Added file ./build.xml
Updated file ./proguard.cfg
Updated build.properties

Test Coverage Report
  • Open terminal to test project directory
% ant coverage
...compile/install project...
...compile/install test project...
coverage:
        Running tests...
...cleanup...
  • Open <test project root>/coverage/coverage.html
Add Robotium
  • Download robotium-solo-<version>.jar to <test project root>/libs
  • Add to test project
  • File -> Properties
  • Select Java Build Path -> Libraries -> Click Add Jar...
  • Open Big Mean Robot -> libs
  • Select robotium-solo-<version>.jar -> Click OK
  • Click OK
Create Robotium Test

2 comments:

  1. That still doesn't show how you got your CI to run the robotium tests.

    ReplyDelete
    Replies
    1. Give me a couple days. I'll try to get around to doing a writeup on my setup.

      Basically though:
      Linux
      - Sun/Oracle Java 6
      - Android (Latest)
      - Tomcat
      - Jenkins
      - Hudson Xvnc Plugin
      - Hustdon Port Allocator Plugin
      - Android Emulator Plugin
      - Jenkins Emma Plugin

      In the configuration for the particular project:
      X - Run Xvnc during build
      X - Run Android emulator during build (Setup emulator as you wish, I suggest using snapshots)

      # Invoke Ant
      Targets: clean emma debug install test
      Set path to your build file relative to the workspace.

      Delete