Running an Android test program from Eclipse vs. console

Given the Android project in the Eclipse assembly of two projects: Project 1 is a Java library that compiles perfectly on Android. Project 2 is a test case for the library, essentially classes that extend AndroidTestCase and output the results to the Android console. Project 1 is a Java project, project 2 is an Android project depending on project 1.

Problem Description: If I run tests from Eclipse as Android JUnit Tests, they run as they should, without errors. However, if I want to execute them again using the command line:

adb shell am instrument -w bla.bla/android.test.InstrumentationTestRunner

I get a lot

 Cannot load class. Make sure it is in your apk. Class name: xyz java.lang.ClassNotFoundException: xyz at java.lang.Class.classForName(Native Method) at java.lang.Class.forName(Class.java:234) at android.test.ClassPathPackageInfoSource.createPackageInfo .... Caused by: java.lang.ClassNotFoundException: xyz in loader dalvik.system.PathClassLoader[/system/framework/android.test.runner.jar:/data/app/bla.apk] at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240) .... 

errors in logcat.

Remarks: Eclipse installs .apk. Later, I run the same .apk already installed, so the available classes should be the same. Classes are dynamically queried using Class c = Class.forName("xyz") .

So the question is, how does Eclipse execute the installed .apk differently so that the appropriate classes are at runtime?

+6
source share
1 answer

Are you sure xyz.class is in CLASSPATH?

I had the same problem and it was that!

+2
source

Source: https://habr.com/ru/post/900939/


All Articles