Android Eclipse 插件:未指定 Instrumentation Test Runner
当尝试使用 Android 项目从 Eclipse 运行单元测试时,我收到此错误。 Android 首选项中的 Instrumentation Test Runners 列表为空。
[2009-06-17 23:57:51 - MyApp] 错误: 应用程序未指定 android.test.InstrumentationTestRunner 仪表或不声明 使用库 android.test.runner
也令人烦恼地决定,因为我尝试运行一次单元测试,这就是我一直想做的事情。
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
It's also annoyingly decided that because I tried to run a unit test once, that's what I always want to do.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
您可能缺少
AndroidManifest.xml
中的uses-library
和instrumentation
节点:You're probably missing the
uses-library
andinstrumentation
nodes in yourAndroidManifest.xml
:在
运行配置
中,您可能有Android JUnit Test
,如果其中有任何新的启动配置条目,请将其删除,然后运行它将运行的应用程序。注意 - 如果您在将正确的行添加到清单之前尝试运行测试用例(如约瑟夫的答案中所述),这可能是解决方案。 如果您已完成此操作,请删除配置(这将抱怨其标头中未指定仪器测试运行程序),然后再次将其作为 Android Junit 测试运行,它将创建一个有效的配置,选取您所选择的正确内容。已添加到清单中(请参阅约瑟夫的回答)。
In the
Run Configuration
you may haveAndroid 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).
我在这次讨论中注意到的一件事可能会让一些人感到困惑,那就是您需要确保清单中的“仪器”元素是“清单”的子元素,而不是“应用程序”的子元素。 (这里的例子是正确的,但是很容易混淆。)
http: //developer.android.com/guide/topics/manifest/instrumentation-element.html
如果您将检测内容放入应用程序中,则不会拾取它,并且您在 Eclipse ADT 插件中进行选择以进行检测跑步者可能是空白的。 (但没有抛出或显示错误等)
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.)
只需在 Eclipse IDE 中右键单击您的测试类,然后单击“Run As”即可。 选择“运行配置”后,将在 Eclipse 中启动配置窗口,您需要单击“Instrumentation Runner”旁边的单选按钮,然后从下拉列表中选择配置的 Instrumentation Runner。 现在单击“应用”,然后单击“运行”。
我想这会解决你的问题。
谢谢,
斯姆鲁蒂
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
它不在你的代码中,只是 eclipse 有一点 bug。 在您的运行配置中,它可能会尝试运行 jUnit 测试,但选择“运行应用程序”,该错误就会消失。
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.
除了确保在测试应用程序的清单中声明以下项目之外,请检查运行配置,确保“Instrumentation runner”字段设置为
这就是我在弄清楚为什么我的测试无法运行时遇到的情况。
显现:
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
This what I ran into when figuring out why I test wouldn't run.
Manifest:
问题是当你创建项目时,你会有一个 AVD,所以这些配置将会丢失。 我建议的方法是首先创建 AVD,然后创建 android 项目:)。
如果您已经创建了该项目并且没有编写太多代码,我建议删除它并创建一个新项目。
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.