Saturday, November 6, 2010

Android Instrumentation Testing

This article will talk about a strange "permission denial" issue which occurs when  trying to run android instrumentation on eclipse. Of course it'll also disclose the solution to it :).

So, what's the problem?
Whenever you try to run the android test-suite for your application, you see an error message like the following in the 'Console' area of your eclipse IDE.
"Test run failed: Permission Denial: starting instrumentation ComponentInfo{<testPackage>/android.test.InstrumentationTestRunner} from pid=123, uid=123 not allowed because package <testPackage> does not have a signature matching the target <targetPackage>"

Reason?
The error message is pretty self-descriptive. As you might have figured out, it's basically due to a signature mismatch between the <targetPackage> and <testPackage>. In simple words, eclipse is using different certificates for signing up your application and for it's test-suite.

Solution?
Generally, when you are running test-cases on your application, you would want to use debug certificates. Eclipse, by default uses debug certificates. So, best way to solve this is to start from scratch. For that, just do the following. In the 'Package Explorer' right click on your target application -> Source -> Clean up. Repeat the same thing for your test application as well. After this, rebuild both of them. Then you'll be right back on the track.

Happy coding!

1 comment:

  1. I fail to see how a "Source -> Clean Up" would modify certificates...

    The clean up feature is purely for modifying code formatting.

    ReplyDelete