Android testing

After a nice presentation introducing TDD on Android, I wanted to jump right in with LogMyLife. Of course, the very first thing I tried, I got a lovely error:

java.lang.RuntimeException: Unable to resolve activity for: 
Intent { action=android.intent.action.MAIN flags=0x10000000
 comp={net.sosiouxme.logmylife.activity/net.sosiouxme.logmylife.activity.Main} }

I just love errors like this which pretty much just give me no idea what’s going on. But I got a clue from this StackOverflow question on the same error – when I followed the tutorial, I adjusted it for LogMyLife’s package structure, in which all Activities are in a sub-package (.activity) from the main one. So my constructor looked like this:

public MainTest() {
  super("net.sosiouxme.logmylife.activity", Main.class);

The tutorial doesn’t really say what these parameters are. Evidently the first one should be the package of the app (in this case, “net.sosiouxme.logmylife”), not the activity being tested; I guess this makes sense for the instrumentation to hook into. But it’s an easy mistake to make…

Next problem: one of the things I’m most interested in testing is my BroadcastReceivers, particularly the one that receives BOOT_COMPLETE (hard to attach a debugger in time to see that one go through). Oddly, while there are instrumentation classes for the other three major Android components, there’s none for a BroadcastReceiver. I asked about it on StackOverflow, we’ll see if there’s an answer (I seem to have a talent for asking questions that get no answer). Maybe this can just be mocked somehow?