Reputation: 495
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?
Upvotes: 6
Views: 6047
Reputation: 11
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.*" />
Upvotes: 1
Reputation: 408
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.
Upvotes: 12
Reputation: 495
Ah so far I've been able to get it to work by having both the android.test.InstrumentationRunner runner AND the customer test runner described in the manifest file. I seems that running from Eclipse will use the android.test.InstrumentationRunner and running from the command line will use the custom test runner if its setup in the ant script.
Upvotes: 0
Reputation: 1857
Since I can't see your whole project setting, here's a couple check list I'd try.
Do you have a separate Test Project in Eclipse? Is the above instrumentation block in your source project's manifest file or in the test project's manifest file?
Did you include the <uses-library android:name="android.test.runner" /> block?
Did you put the test project's instrumentation block outside the <application> block and the <uses-library> block inside the test project's application block?
Did you try creating a Test Project in Eclipse through the "New Project -> Android Test Project", and just changing the instrumentation class there after adding the source code? If you don't change the instrumentation class does it work?
Are you running the test in Eclipse by doing "Run As -> Android JUnit test"?
If you already did all that, I think pasting your whole AndroidManifest file would help clarify a bit, and whether or not you have 2 separate projects or not.
Upvotes: 0