I’m assuming that you already know how to create automated tests for Android applications. If you don’t you can read something in the Android Testing documentation.

I was trying to run some Android tests in an application that has several activities running in separate processes. If you have ever tried to do such thing, you know that it isn’t very straightfoward. It complains that it can’t instrument an activity whose intent was resolved in another process. Bummer!

I’ve spent some time thinking how to test this, and I figured a way. The activities that where put into testing didn’t need to run in separate processes when running alone, so simply extending the target activity and declaring it on the AndroidManifest without the android:process attribute made possible to run the automated tests on this new activity. One caveat: this must be done in the application package, not in the application’s test package. So this will add a little bit of turmoil to your application.

The possibility of running your application on the main thread may or may not be your case. If it isn’t, then you’ll have to find your own way. In this case, there’s one thing I would like to ask: if, by any chance, you solve this problem without the dirty trick, please leave a comment on this article. It may help people in the future, and I’ll gladly take links, if that’s the case.

You can get the sample code on github (as soon as I post it there).

Zooomr : ,