views:

9197

answers:

8

I'm getting this error when trying to run unit tests from Eclipse with an Android Project. The list of Instrumentation Test Runners is empty in the Android preferences.

[2009-06-17 23:57:51 - MyApp] ERROR: Application does not specify a android.test.InstrumentationTestRunner instrumentation or does not declare uses-library android.test.runner

Google-fu failing me.

It's also annoyingly decided that because I tried to run a unit test once, that's what I always want to do... Grr

+4  A: 

You're probably missing the following in your AndroidManifest.xml:

<instrumentation android:name="android.test.InstrumentationTestRunner"
    android:targetPackage="your.package"
    android:label="your tests label" />
and
<uses-library android:name="android.test.runner" />
Josef
Thanks so much :)
Rob Stevenson-Leggett
+2  A: 

Hi, Just do a right click on your test class from eclipse IDE and click on "Run As". After this select "run Configuration" which will launch a Confiuration Window in eclipse and you need to click on the radio button next to the "Instrumentation Runner" and select the configured Instrumentation Runner from the drop down. Now click on apply and then click on Run . I think this will solve your problem.

Thanks, Smruti

+6  A: 

Hi, In the "Run Configuration" you may have "Android JUnit Test", if there are any new launch configuration entries inside this, you delete it and then run your application it will run.

--Pradeep

D.S.Pradeep Kumar
It is *very* unlikely that this is the cause for the error message included in the question.
Josef
A: 

The problem is when you created the project, you would have had a AVD, so these configuration would be missing. My suggested way is first create the AVD and then create the android project :).

If you would have already created the project and if does not have much code you have written I would suggest to delete it and create a new one.

Krishna Anisetty
A: 

its not in your code its just eclipse is a little buggy its in your run configurations it could be trying to run jUnit test but select run application and that error will go away

pier shaw
+1  A: 

One thing I noticed in this discussion that might be tripping some people up is that you need to make sure the "instrumentation" element in your manifest is a child of "manifest" and not of "application." (The examples here are correct, but this easy to mix up.)

http://developer.android.com/guide/topics/manifest/instrumentation-element.html

If you put your instrumentation stuff inside application, it won't be picked up, and your choices in the Eclipse ADT plugin for instrumentation runner may be blank. (But no error is thrown or shown, etc.)

Charlie Collins
and uses-library needs to be a child of application
Jeb
A: 

I faced the same problem and Josef's solution worked for me. I added the uses-library element inside application element and the instrumentation element outside of it. Then I deleted any existing Run Configuration under Android JUnit Test and reran my test class. However, I am getting the following error now:

Test run failed: Unable to find instrumentation target package: testandroid.util.AndroidException: INSTRUMENTATION_FAILED: xxx/android.test.InstrumentationTestRunner

Can anyone help?

russoue
A: 

i faced the same problem " instrumentation specification Error " thanks to josef his solution really worked. but instead of coding i recommend clicking instrumentation tab (UI) in "AndroidManifest.Xml" and fill up required details. and also using " uses-library android:name="android.test.runner" tab.

Riz Khan