Android 无法找到检测目标包:com.xyz
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10172636/
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
Unable to find instrumentation target package: com.xyz
提问by Sindhu Perumalla
I wrote a testcase class for a library project,I created this test case project separately.
我为一个库项目编写了一个测试用例类,我单独创建了这个测试用例项目。
when I am trying to run this test project.the console is showing the error "Unable to find instrumentation target package: <with package name>"
,
当我尝试运行此测试项目时。控制台显示错误"Unable to find instrumentation target package: <with package name>"
,
I google for the solution also,in some sites they gave check the tag android:targetPackage attribute in AndroidManifestFile .
我也在谷歌上搜索解决方案,在一些网站中,他们检查了 AndroidManifestFile 中的标签 android:targetPackage 属性。
I checked the manifest the instrumentation tag is correct it is targeting correctly the libraryproject package.
我检查了清单,仪表标签是正确的,它正确地定位到 libraryproject 包。
Could any one help in this,to make my testcase project for a library runnable
任何人都可以在这方面提供帮助,使我的库的测试用例项目可运行
采纳答案by yorkw
You have to create and setup an Application Project that depends on the Library Project, in order to test the Library Project. Quoting from official developer's guide:
您必须创建和设置依赖于库项目的应用程序项目,以便测试库项目。引用官方开发者指南:
Testing a Library Project
There are two recommended ways of setting up testing on code and resources in a library project:
You can set up a test project that instruments an application project that depends on the library project. You can then add tests to the project for library-specific features.
You can set up a set up a standard application project that depends on the library and put the instrumentation in that project. This lets you create a self-contained project that contains both the tests/instrumentations and the code to test.
测试库项目
有两种推荐的方法可以在库项目中设置代码和资源的测试:
您可以设置一个测试项目来检测依赖于库项目的应用程序项目。然后,您可以将测试添加到项目中以获取特定于库的功能。
您可以设置一个依赖于库的标准应用程序项目,并将检测放在该项目中。这使您可以创建一个包含测试/仪器和要测试的代码的自包含项目。
Android Library Projects are not built directly, but are built along with the Main Application Project. In another words, you cannot compile it directly to its own .apk and run it on an Android device. On the other hand, instrumentation tests work by running the test project application ("Run As..."->"Android JUnit Test" in Eclipse) after installing both app.apk and test.apk on the device, and then using test.apk to manipulate the app.apk—hence the "instrumentation" part of the test name.
Android 库项目不是直接构建的,而是与主应用程序项目一起构建的。换句话说,您无法将其直接编译为自己的 .apk 并在 Android 设备上运行。另一方面,在设备上安装 app.apk 和 test.apk 后,仪器测试通过运行测试项目应用程序(Eclipse 中的“Run As...”->“Android JUnit Test”),然后使用 test .apk 来操作 app.apk——因此是测试名称的“检测”部分。
Update:
更新:
Note that if you use second approach, you can create a Test Project testing Library Project without creating a third Application Project, because a Test Project itself is also a regular Application Project.
请注意,如果您使用第二种方法,您可以创建一个测试项目测试库项目,而无需创建第三个应用程序项目,因为测试项目本身也是一个常规的应用程序项目。
回答by Dawid Drozd
When you create android test project remember to set good target package
创建android测试项目时记得设置好目标包
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.test" <-------------------
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.example.test" > <-----------------
</instrumentation>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<uses-library android:name="android.test.runner" />
<activity android:name="TestActivity" />
</application>
</manifest>
回答by gsaslis
In my case, I was running with gradle, running just the connectedInstrumentTest task with
就我而言,我使用 gradle 运行,只运行 connectedInstrumentTest 任务
./gradlew connectedInstrumentTest
./gradlew connectedInstrumentTest
and I was getting the "Unable to find instrumentation info" error... The problem was I also needed to include the installDebug task to be executed before the connectedInstrumentTest task, like this:
并且我收到了“无法找到检测信息”错误......问题是我还需要在 connectedInstrumentTest 任务之前包含要执行的 installDebug 任务,如下所示:
./gradlew installDebug connectedInstrumentTest