A few little tweaks to automate Android instrumentation testing via Robotium & Maven

Having recently revived an android project I haven’t opened in close to 6 months, I was left scratching my head as to why I couldn’t run any of my integration tests.

Thinking back, I remembered having problems getting robotium to instrument the clicking of a button, as simple as it sounds, theres a few little gotchas involved. Firstly, I needed to modify the test code to click on text, rather than a button, as it has been suggested by various users on StackOverflow that there does tend to be odd side effects when clicking buttons:

public void testClickGetSurveyTakesToSurveyRunner() {
 solo.clickOnText("Get Survey");
 solo.assertCurrentActivity("Current activity was not correct", SurveyRunner.class);

Next, I needed to add this into the test projects AndroidManifest

<uses-sdk android:targetSdkVersion="10" />

And then to add this into the main projects AndroidManifest:

<supports-screens android:anyDensity="true"/> 

Both of these tweaks are mentioned on the Robotium FAQ, so it might be worth glancing there to see if any enhancements get made in the future

After making those changes, I stumbled into another error that reared its ugly head in the logcat:

ERROR/AndroidRuntime(1185): FATAL EXCEPTION: main
 java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation
 at com.roosearch.android.activity.SurveyRunner.onResume(SurveyRunner.java:38)
 at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1150)
 at android.app.Activity.performResume(Activity.java:3832)
 at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2110)
 at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2135)
 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1668)
 at android.app.ActivityThread.access$1500(ActivityThread.java:117)
 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
 at android.os.Handler.dispatchMessage(Handler.java:99)
 at android.os.Looper.loop(Looper.java:130)
 at android.app.ActivityThread.main(ActivityThread.java:3683)
 at java.lang.reflect.Method.invokeNative(Native Method)
 at java.lang.reflect.Method.invoke(Method.java:507)
 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
 at dalvik.system.NativeStart.main(Native Method)

There seems to be a rather peculiar requirement, that any dependencies your using on your main application, also need to be in the test projects pom.xml, but marked with a scope of provided. After making that change as advised here and rebuilding, both the app and instrumentation app build and test successfully.

I was also pleasantly surprised that I could run the instrumentation tests via IntelliJ IDEA 12 Ultimate, last time I tried that (on an older version albeit), it wasn’t so simple…

Not posted in a while, busy busy busy!

Hi folks,

It’s been a little while since I made any detailed posts, and it’s not through lack of wanting. I’ve been pretty busy with a new project at work, and I’m also preparing to (finally) sit my SCJP at the end of November, so I haven’t had any time to write any android tutorials.

As ever, my “to do list” is massively increasing, I have a BIG Grails/Groovy personal project coming up after my SCJP, which will be a Grails web app, along with an android mobile client, with some QR code functionality and social integration added into the mix, so I’ll have plenty of interesting things to blog about in the coming winter months.

I’ve recently spent a lot of time working with IBM Worklight, so expect something on that, I also have ideas floating around in my head for Objective-C, C++, Python, MongoDB, Spring, more Android stuff, and covering off some of the iOS stuff I worked on over the summer.

So much to do, so little time…

Thetford Forest Red run

I’ve done the red route a couple of times this year, its a really nice ride, and contrary to the Forestry Commissions comment of it being “taxing and difficult”, its actually quite tame.

Thetford Forest Red Cycle Route
Thetford Forest Red Cycle Route

The route itself is about 6 miles, or 11 miles if you decide to take the extra loop. I did the full 11 miles in just under 2 hours, but that was a pretty casual ride with several stops for water.

The route, as do all routes, start from the High Lodge center. The start of the route is slightly confusing, follow the red posts away from the High Lodge, and towards the car park and the road you came in on, thats where the route starts (for some reason, there are red posts pointing towards the back of the High Lodge center, you don’t want to go that way)

There are some patches of sand at the start (or end, since the route is a loop), you’ll need to watch out for these as your wheels can slip out from under you if you hit it too fast, and make sure you’re going straight. If you hit sand on a corner or a turn it could be interesting ;)

Thetford Forest Red Cycle Route
Thetford Forest Red Cycle Route

After about a mile, you’ll enter the first technical part. You’re directed into a section of close trees, the path is very windy so you’ll need to take it slow. After a quarter of a mile or so you’ll come back out into the open, and to single lane track again. You’ll come across a few patches on the route that are like this.

About half way through, you’ll cross over the green route, and enter some trees. This is probably the hardest part of the route, its very windy and downhill, there are also a few minor drops. The track was created with some logs underneath in certain places to elevate the track, but some have become exposed so there is a 1 foot drop in certain places. Its nothing particulary difficult, just hold tight!