Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
294 views
in Technique[技术] by (71.8m points)

android - Unable to find instrumentation target package: com.xyz

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

I google for the solution also,in some sites they gave check the tag android:targetPackage attribute in AndroidManifestFile .

I checked the manifest the instrumentation tag is correct it is targeting correctly the libraryproject package.

Could any one help in this,to make my testcase project for a library runnable

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...