Android Eclipse 插件:未指定 Instrumentation Test Runner

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1009970/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 02:35:40  来源:igfitidea点击:

Android Eclipse Plugin: Instrumentation Test Runner not specified

androideclipseunit-testingjunit

提问by Rob Stevenson-Leggett

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.

尝试使用 Android 项目从 Eclipse 运行单元测试时出现此错误。Android 首选项中的 Instrumentation Test Runners 列表为空。

[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

[2009-06-17 23:57:51 - MyApp] 错误:应用程序未指定 android.test.InstrumentationTestRunner 检测或未声明使用库 android.test.runner

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

也很烦人地决定,因为我试图运行一次单元测试,这就是我一直想做的事情。

采纳答案by D.S.Pradeep Kumar

In the Run Configurationyou 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.

Run Configuration你可能有Android JUnit Test,如果里面有任何新的启动配置条目,你删除它,然后运行你的应用程序,它将运行。

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

注意 - 如果您尝试在将正确的行添加到清单之前运行测试用例,这可能是解决方案,如 Josef 的回答中所述。如果你这样做了,删除配置(它会抱怨没有在它的头中指定检测测试运行器),然后再次将它作为 Android Junit 测试运行,它会创建一个有效的配置,选择正确的东西,你已添加到清单中(请参阅约瑟夫对此的回答)。

回答by Josef Pfleger

You're probably missing the uses-libraryand instrumentationnodes in your AndroidManifest.xml:

您可能缺少uses-libraryinstrumentation节点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>

回答by Charlie Collins

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

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

如果你把你的检测工具放在应用程序中,它不会被拾取,并且你在 Eclipse ADT 插件中为检测运行器所做的选择可能是空白的。(但没有抛出或显示错误等)

回答by user190362

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.

只需在 Eclipse IDE 中右键单击您的测试类,然后单击“运行方式”。在此之后选择“运行配置”,这将在 eclipse 中启动一个配置窗口,您需要单击“Instrumentation Runner”旁边的单选按钮并从下拉列表中选择配置的 Instrumentation Runner。现在单击应用,然后单击运行。我认为这将解决您的问题。

Thanks, Smruti

谢谢,斯姆鲁蒂

回答by pier shaw

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.

它不在您的代码中,只是 Eclipse 有点问题。在您的运行配置中,它可能会尝试运行 jUnit 测试,但选择运行应用程序,该错误将消失。

回答by Yoong

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" />

回答by Krishna Anisetty

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

问题是当你创建项目时,你会有一个 AVD,所以这些配置会丢失。我建议的方法是首先创建 AVD,然后创建 android 项目 :)。

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.

如果您已经创建了该项目并且没有编写太多代码,我建议您将其删除并创建一个新的。