Android Eclipse Plugin: Instrumentation Test Runner not specified

前端 未结 7 1277
抹茶落季
抹茶落季 2020-12-04 21:46

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.

相关标签:
7条回答
  • 2020-12-04 21:49

    It's not in your code, it's just eclipse is a little buggy. In your run configurations it could be trying to run a jUnit test, but select Run Application and that error will go away.

    0 讨论(0)
  • 2020-12-04 21:53

    Besides ensuring that the below items are declared in the manifest of your test app, check in the Run Configuration that the "Instrumentation runner" field is set to

    "com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner". 
    

    This what I ran into when figuring out why I test wouldn't run.

    Manifest:

    <instrumentation android:name="android.test.InstrumentationTestRunner"
     android:targetPackage="your.package"
     android:label="your tests label" />
    
     and...
    
    <uses-library android:name="android.test.runner" />
    
    0 讨论(0)
  • 2020-12-04 21:57

    You're probably missing the uses-library and instrumentation nodes in your AndroidManifest.xml:

    <manifest ...>
        <application ...>
            <!-- ... -->
            <uses-library android:name="android.test.runner" />
        </application>
        <instrumentation android:name="android.test.InstrumentationTestRunner"
            android:targetPackage="your.package"
            android:label="your tests label" />
    </manifest>
    
    0 讨论(0)
  • 2020-12-04 21:58

    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.)

    0 讨论(0)
  • 2020-12-04 21:58

    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.

    0 讨论(0)
  • 2020-12-04 22:12

    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.

    NOTE - This is likely to be the solution if you tried to run the test case before adding the correct lines to the manifest as described in the answer from Josef. If you have done this, delete the configuration (which will be complaining that no instrumentation test runner has been specified in its header) and then run it as an Android Junit Test again and it will create a valid configuration picking up the correct stuff that you have added to the manifest (see Josef's answer for this).

    0 讨论(0)
提交回复
热议问题