Tuesday, July 5, 2011

Android: Problems of run Unit Tests

Hi,
I have created separate project for testing my Android Application and tried to start it.
After starting I have received next error:

Test run failed: Unable to find instrumentation info for: 
ComponentInfo {<my package>/android.test.InstrumentationTestRunner}

After few hours of investigation I have found solution for this situation.

Problem:
So, Problem is package in the manifest files.  The package in “real” project manifest file and test manifest file are equal. For instance look at the package com.blogspot.jugvn in both manifests

Test manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest 
xmlns:android="http://schemas.android.com/apk/res/android"

package="com.blogspot.jugvn"

android:versionCode="1"

android:versionName="1.0">
<uses-sdk 
android:minSdkVersion="7" />
<instrumentation 
android:targetPackage="com.blogspot.jugvn" 
android:name="android.test.InstrumentationTestRunner" 
/>
<application android:icon="@drawable/icon" 
android:label="@string/app_name">
<uses-library android:name="android.test.runner" 
/>
</application>
<!-- 
Add permissions for send sms messages--> 

<uses-permission android:name="android.permission.SEND_SMS" 
/>
<uses-permission 
android:name="android.permission.WRITE_SMS" />
</manifest>

Project Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest 
xmlns:android="http://schemas.android.com/apk/res/android"

package="com.blogspot.jugvn"

android:versionCode="1" android:versionName="1.0">

<application android:label="@string/app_name" android:icon="@drawable/visa" 
android:debuggable="true">

<activity android:name=".AccountList" 
android:label="@string/app_name">

<intent-filter>

<action android:name="android.intent.action.MAIN" 
/>

<category android:name="android.intent.category.LAUNCHER" 
/>

</intent-filter>

</activity>
</application>
<uses-sdk 
android:minSdkVersion="7" android:targetSdkVersion="7" 
/>
<!-- Allows an application to 
read SMS messages. -->
<uses-permission 
android:name="android.permission.READ_SMS" />
</manifest>

Solution:
Change package in test project to something else, I have used next convention: put test instead of first part of package like this :

test.blogspot.jugvn

And result manifest file should be like this

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="test.blogspot.jugvn 
"

android:versionCode="1"

android:versionName="1.0">
<uses-sdk 
android:minSdkVersion="7" />
<instrumentation 
android:targetPackage="test.blogspot.jugvn " 
android:name="android.test.InstrumentationTestRunner" 
/>
<application android:icon="@drawable/icon" 
android:label="@string/app_name">
<uses-library 
android:name="android.test.runner" />

</application>
<!-- Add permissions for send sms 
messages--> 
<uses-permission 
android:name="android.permission.SEND_SMS" />

<uses-permission android:name="android.permission.WRITE_SMS" 
/>
</manifest>

That is all manipulation for fixing this problem.

Cheers!

1 comment:

  1. I have not same packages:
    com.app
    com.app.test

    And still experienced this issue

    ReplyDelete