Solution for Test running failed: Unable to find instrumentation info for: ComponentInfo{…./com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner}

Whilst using Espresso I have come across an issue a number of times and each time it takes me a few minutes to remember what the solution is. So, I thought I should put it down here!

Solution

Ensure that both your build.gradle in the app folder and the run configuration in Android Studio need to declare the com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner.

In the build.gradle file in your app folder you need to add the line

testInstrumentationRunner “com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner”

In your android studio run configuration you will need to add com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner to the Specific Instrumentation Test Runner field.

Explanation

The com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner is a requirement when using Espresso and although the error message (Unable to find instrumentation info for: ComponentInfo{…./com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner}) is highlighting that the Activity might not have instrumentation set you’ll actually find that it is when you run the command 

 adb shell pm list instrumentation

I am using Android Studio for my development and therefore a lot of the solutions out there talk about modifying the test folders AndroidManifest.xml file. When using Android Studio and the Gradle build system this isn’t needed because the test AndroidManifest.xml is auto generated. As long as you specify the new Google Instrumented Test Runner in both of these locations the problem should resolve itself.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s