Mittwoch, 12. Mai 2010

Android JUnit Test Runner - java.lang.ClassNotFoundException

Today I've been setting up a test project for my upcoming android-project. First thing I did was using the Eclipse wizard to create a new Android test project for an existing android project.
I quickly threw in a TestSuite that would run all Tests 'below' the current package...
package org.anddev.andengine.test;

import junit.framework.Test;
import junit.framework.TestSuite;
import android.test.suitebuilder.TestSuiteBuilder;

public class AllTests extends TestSuite {
 public static Test suite() {
  return new TestSuiteBuilder(AllTests.class).includeAllPackagesUnderHere().build();
 }
}
... and a dummy TestCase ...
package org.anddev.andengine.test.bla;

import junit.framework.Assert;
import android.test.AndroidTestCase;

public class SomeTest extends AndroidTestCase {

    public void testSomething() throws Throwable {
       Assert.assertTrue(1 + 1 == 2);
    }

    public void testSomethingElse() throws Throwable {
       Assert.assertTrue(1 + 1 == 3);
    }
}

Either running the Android test project right from Eclipse or from the command-line resulted in:
E:\sdk\android\tools>adb shell am instrument -w org.anddev.andengine.test/android.test.InstrumentationTestRunner


INSTRUMENTATION_RESULT: shortMsg=Unable to instantiate instrumentation ComponentInfo{org.anddev.andengine.test/android.test.InstrumentationTestRunner}: java.lang.ClassNotFoundException: android.test.InstrumentationTestRunner in loader dalvik.system.PathClassLoader@4001b4f8
INSTRUMENTATION_RESULT: longMsg=java.lang.RuntimeException: Unable to instantiate instrumentation ComponentInfo{org.anddev.andengine.test/android.test.InstrumentationTestRunner}: java.lang.ClassNotFoundException: android.test.InstrumentationTestRunner in loader dalvik.system.PathClassLoader@4001b4f8
INSTRUMENTATION_CODE: 0

So what was the problem and how did I fix this?

Due to the fact that the project I wanted to test was a kind of libary, which had no need for an application or activity tag or similar i had deleted it from the AndroidManifest.xml, like this:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
 package="org.anddev.andengine"
 android:versionCode="1"
 android:versionName="1.0">

 <uses-sdk android:minSdkVersion="4" />
</manifest> 
... so the only thing I had to change was an empty <application> tag to the AndroidManifest.xml !
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
 package="org.anddev.andengine"
 android:versionCode="1"
 android:versionName="1.0">

 <uses-sdk android:minSdkVersion="4" />
 <application />
</manifest> 

Hope this helps =)

Best Regards,
Nicolas

Kommentare:

  1. We sell ray ban 2132 wayfarer Sunglasses Resin-tortoise/green hzxmwic into uk area, abusolutely high quality glasses online. Shop in our ray ban sunglasses store,Flaunting on each eye of the followers of fashion can be found with at least one
    pair of ray ban wayfarer 2151 . They offer both sturdy and We are selling ray ban 3025 aviator Sunglasses Glass-gold/dark brown here.
    Choose the Ray Ban you like for free.The cool and trendy ray ban aviator 3026 made by famous designer companies make up your personality. Nowadays, sunglasses with UV ray protection are Shop for ray ban 3183 polarized. Find the best deals on ray ban 3183 polarized , ray ban
    and more on iOffer.com.Buy ray ban rb 3194 sunglasses. We carry a huge selection of all Ray Ban sunglasses. 100% free US shipping and easy returns!

    AntwortenLöschen
  2. I like your blog opportunity.This is one of the thoughtful post.Nice to discuss with us.
    Android app developers

    AntwortenLöschen
  3. Very useful coding for Android.I am actually looking for this.
    right here

    AntwortenLöschen
  4. Studying the particular post Now i'm able to indicate you have excellent ability as a copywriter. We observed my buddies concerning your internet site. I'll seem once more to find out fresh content articles. Thank you.

    AntwortenLöschen
  5. Thank you for this fantastic and needful read. I was very encouraged to find this site. Thanks a lot. Report writing

    AntwortenLöschen
  6. This code is so simple and easy to understand..It has solved my problem and i am going to make changes in my websites code through this..Essay writing services

    AntwortenLöschen
  7. Ranthambore, as one of the best national parks in the world to see Bengal tigers, wild, in their natural home. Here can see Bengal tigers as well as Sundari, Machali, Star male, Jumru and so on. Each of Ranthambore denizens is well recognized and The Ranthambhore Bagh, with its trained team, is perhaps your best bet to know who is who.
    Ranthambore Tiger Reserve
    Ranthambore Safari Booking

    AntwortenLöschen