Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using custom InstrumentationTestRunner in Eclipse causes Error

I have a seperate Test Project in Eclipse that has been running successfully for a while in both command line and Eclipse. While using Jenkins to run my tests, I've run into the issue where the standard InstrumentationTestRunner does not output in a Jenkins supported xml format. I've read on the internet to use a custom InstrumentationTestRunner. This works in the command line using ADB, but fails in Eclipse when running as Android Test Case.

I've downloaded a custom instrumentation test runner (com.neenbedankt.android.test) and added it to the AndroidManifest like this:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.testedapplication.test"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="7" />

    <instrumentation
        android:name="com.neenbedankt.android.test.InstrumentationTestRunner"
        android:targetPackage="com.testedapplication" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <uses-library android:name="android.test.runner" />
    </application>    
</manifest>

Here is the error that I get in Eclipse:

[Test Project] is not configured correctly for running tests: A targetPackage attribute for instrumentation android.test.InstrumentationTestRunner in its AndroidManifest.xml could not be found!

You can see that i've set the targetPackage there, so I'm not sure what else I can do?

like image 679
SpecialEd Avatar asked Oct 23 '12 02:10

SpecialEd


2 Answers

Add both instrumentation in your AndroidManifest.xml.

<instrumentation
    android:name="android.test.InstrumentationTestRunner"
    android:targetPackage="com.example.myapp" />

<instrumentation
    android:name=".MyRunner"
    android:targetPackage="com.example.myapp" />

Then go to Package explorer --> $(Your Test Prject$) --> Run As --> Run configurations --> Android JUnit Test --> $(Your Test Project) --> Instrumentation Runner and select your runner there.

like image 108
Hui.Li Avatar answered Oct 29 '22 20:10

Hui.Li


To make eclipse select custom runner by default when doing run as/android junit - simply switch the order in manifest file. Make sure yours is first

<instrumentation
android:name="*.Custom.TestRunner"
android:targetPackage="com.*" />

<instrumentation
android:name="*.InstrumentationTestRunner"
android:targetPackage="com.*" />
like image 22
Y K Avatar answered Oct 29 '22 19:10

Y K