JUnit and ClassNotFoundException

by Bo » Wed, 07 Jan 2009 18:26:59 GMT

Sponsored Links
 I am trying to run a unit test in Eclipse. I followed Android FAQ
( http://code.google.com/android/kb/troubleshooting.html #addjunit) to
get JUnit working. Unfortunately, it works only if tested code does
not reference any android classes. As soon as it does, I get the
following exception, when running the test (if the class in question
implements Parcelable):

Caused by: java.lang.ClassNotFoundException: android.os.Parcelable
        at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:316)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:288)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:374)
        ... 33 more

I tried including android.jar file explicitly, but then I got an
exception claiming that RectF (an instance variable in my class) is a
stub. Anybody knows how to setup Eclipse to run a unit test with
classes that either implement, extend or use android classes?


JUnit and ClassNotFoundException

by Gavin Aiken » Sat, 07 Mar 2009 05:25:09 GMT

 Hi Bo,

Did you resolve this issue? I'm having a similar problem.

My test suite is a separate eclipse project, I need to test my android
program against a desktop Java program in order to verify that I have ported
the application correctly.

To so this I need to use classes from both the JAI library and Android

My test package is currently setup as a java project, I assumed the JAI
library wouldn't compile to dex but that the android classes would compile
to java class files. I'm guessing that the latter is incorrect as any
methods I call return a stub error;

60.  return Bitmap.createBitmap(pixels, 0, width, width, height,

java.lang.RuntimeException: Stub!
    at android.graphics.Bitmap.createBitmap(Bitmap.java:27)

I'm presuming that I can't get this to work, and submit this comment for
reference. If there is a way to use Java Libraries in a test with android
api calls then please let me know!



Sponsored Links

JUnit and ClassNotFoundException

by Xavier Ducrohet » Sat, 07 Mar 2009 06:40:28 GMT

 he only way to test code that uses Android API is on a device or emulator.

Look at instrumentation projects such as the ApiDemos test project

You will need to create an Eclipse project for ApiDemos and one of the
test project.
ADT doesn't fully support this at this point, so you'll need to add
the ApiDemos project to the build path of the test project so that it

You then need to install both apk on the device, and use the "am
instrument ..." command on the device (through adb shell).
More information at


On Fri, Mar 6, 2009 at 1:24 PM, Gavin Aiken <gavin.ai...@imperial.ac.uk> wrote:

Xavier Ducrohet
Android Engineer, Google.


JUnit and ClassNotFoundException

by Gavin Aiken » Fri, 13 Mar 2009 17:19:46 GMT

 i Xav,

Thanks for the tip, I'm still having trouble setting up the test project;

Android Project
Create new android project
Create Project from existing source

! No activity name defined in

I understand that I have to add ApiDemos to the build path but I have to
create the project first. Apologies if this is a bit of a silly question, I
imagine the answer is right in front of me but I can't work it out.

Kind regards,


On Fri, Mar 6, 2009 at 10:40 PM, Xavier Ducrohet <x...@android.com> wrote:


Other Threads

1. Playing Audio During call so that other person on call can hear it

Hi Everyone,
I want to build an application which will play an audio file when call is
connected so that other person on the call can hear this audio file.
experts please guide me how to do that ?
Thanks in advance


2. A Flash Games Site Just For Froyo

yg udh pake froyo..site utk flashgames..hjarrr..


Sent From MY GreenY

"Indonesian Android Community [id-android]" 

3. Xml attribute support for ksoap2 on android

4. Hello World C program using Android Toolchain Issue

5. is it possible to change the application name dynamically???

6. help : wifi tether gagal setelah update ke samdroid-mod

7. Launcher should retain its previous position