Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to find instrumentation target package: com.xyz

Tags:

android

junit

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

like image 331
Sindhu Perumalla Avatar asked Apr 16 '12 10:04

Sindhu Perumalla


3 Answers

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.

like image 66
yorkw Avatar answered Oct 23 '22 00:10

yorkw


When you create android test project remember to set good target package

<?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>
like image 11
Dawid Avatar answered Oct 23 '22 00:10

Dawid


In my case, I was running with gradle, running just the connectedInstrumentTest task with

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

./gradlew installDebug connectedInstrumentTest
like image 6
gsaslis Avatar answered Oct 22 '22 22:10

gsaslis