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
library.

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,
Bitmap.Config.ARGB_8888);

java.lang.RuntimeException: Stub!
    at android.graphics.Bitmap.createBitmap(Bitmap.java:27)
    at
uk.ac.ic.doc.gea05.miffed.operators.concreteoperators.binary.TestIdentityTransform.generateBitmap(TestIdentityTransform.java:60)

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!

Gav






--~--~---------~--~----~------------~-------~--~----~


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
(samples/ApiDemos/tests/)

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
compiles.

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
http://developer.android.com/reference/android/test/InstrumentationTestRunner.html

Xav

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;

File
New
Android Project
Create new android project
Create Project from existing source
android/android-sdk-linux_x86-1.1_r1/samples/ApiDemos/tests

! No activity name defined in
/home/gavin/Work/android/android-sdk-linux_x86-1.1_r1/samples/ApiDemos/tests/AndroidManifest.xml.

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,

Gavin

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


--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. Can not create service interface

Hi,

For some reason I can not create an AIDL service interface, no matter
how simple it is. I am using the latest version of eclipse.

This is what I get, no matter what service functions I add to the aidl
file:

The method attachInterface(IInterface, String) in the type Binder is
not applicable for the arguments (MyServiceInterface.Stub, String)
MyServiceInterface.java

The generated file MyServiceInterface.java, contains numerous errors.
Among them is "testapp.test.net cannot be resolved to a type". Very
strange, since eclipse can do this for everything else.

I have other projects in my workspace where I use AIDL successfully,
but now I can not add this to any project. Very strange. If remove the
aidl file, I can compile and run the app without any problem.

Anyone that have any idea what is going on here?

Anders

-- 

2. drawable-hdpi not appearing in eclipse emulator

Hi there,

So I have this game running on Android 1.6, and I put the different
density images in their respective folders

res/drawable-hdpi/image.png
res/drawable-mdpi/image.png
res/drawable-ldpi/image.png

I made each image a different color so I can tell if it is loading the
right image. When I test my program on different density screens it
only chooses the mdpi images. It scales them to match the correct dpi
but doesn't choose the right folder. It just defaults to mdpi.

In the manifest I have,
android:normalScreens="true" android:anyDensity="false"

Anyone have a similar problem? I'm sure it is something simple that I
am overlooking but I can't figure it out. From what I read on the
Android Support Multiple Screens guide is that you should just have to
put the different density images in their correct folders and Android
will do the rest.

-- 

3. Activity based Tabs

4. Cannot make phone calls between emulator instances compiled from source

5. Power-loss semantics of SQlite on Android

6. Problem installing your own developed app

7. Changing the battery icon position