Cannot run unit tests from Eclipse, only from mvn

28 views
Skip to first unread message

maven-androi...@io7m.com

unread,
Dec 28, 2014, 12:49:17 PM12/28/14
to maven-androi...@googlegroups.com
'Lo.

I have the following simple project arrangement:

https://github.com/io7m/m2e-android-example

Basically, it's a vastly simplified imitation of a real project I'm
working on. The real project has a number of platform-independent
Java modules, with platform-specific code and tests separated into their
own modules.

The project above is arranged:

m2e-android-example/
core/
tests/

The "core" module contains platform-independent code (just a single
class for the sake of this example), and has a packaging type of "jar",
because it's a jar file intended for any system.

The "tests" module contains android-specific test code that simply calls
the class in core to show that tests are actually running and working.

From the command line, I can do:

$ mvn install

And the log output shows that tests are running and passing:

[INFO] Device 4790049d6a99cf10_samsung_GT-I8190 found.
[INFO] 4790049d6a99cf10_samsung_GT-I8190 : Running instrumentation tests in com.io7m.examples.m2e_example.tests
[INFO] 4790049d6a99cf10_samsung_GT-I8190 : Run started: com.io7m.examples.m2e_example.tests, 1 tests:
[INFO] 4790049d6a99cf10_samsung_GT-I8190 : Start [1/1]: com.io7m.examples.m2e_example.tests.HelloTest#testHello
[INFO] 4790049d6a99cf10_samsung_GT-I8190 : End [1/1]: com.io7m.examples.m2e_example.tests.HelloTest#testHello
[INFO] 4790049d6a99cf10_samsung_GT-I8190 : Run ended: 72 ms
[INFO] Tests run: 1, Failures: 0, Errors: 0

However, if I try right-clicking on the AllTests class in Eclipse, and
selecting "Run as Android JUnit test", the code is uploaded:

[2014-12-28 17:30:03 - tests] Android Launch!
[2014-12-28 17:30:03 - tests] adb is running normally.
[2014-12-28 17:30:03 - tests] Performing android.test.InstrumentationTestRunner JUnit launch
[2014-12-28 17:30:03 - tests] Automatic Target Mode: using device '4790049d6a99cf10'
[2014-12-28 17:30:03 - tests] Uploading tests.apk onto device '4790049d6a99cf10'
[2014-12-28 17:30:04 - tests] Installing tests.apk...
[2014-12-28 17:30:06 - tests] Success!
[2014-12-28 17:30:06 - tests] Launching instrumentation android.test.InstrumentationTestRunner on 4790049d6a99cf10
[2014-12-28 17:30:08 - tests] Test run failed: Instrumentation run failed due to 'java.lang.RuntimeException'

Logcat shows:

12-28 17:30:07.696: E/AndroidRuntime(25943): FATAL EXCEPTION: main
12-28 17:30:07.696: E/AndroidRuntime(25943): Process: com.io7m.examples.m2e_example.tests, PID: 25943
12-28 17:30:07.696: E/AndroidRuntime(25943): java.lang.RuntimeException: Exception thrown in onCreate() of ComponentInfo{com.io7m.examples.m2e_example.tests/android.test.InstrumentationTestRunner}: java.lang.RuntimeException: Could not find test class. Class: com.io7m.examples.m2e_example.tests.AllTests
12-28 17:30:07.696: E/AndroidRuntime(25943): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4467)
12-28 17:30:07.696: E/AndroidRuntime(25943): at android.app.ActivityThread.access$1500(ActivityThread.java:144)
12-28 17:30:07.696: E/AndroidRuntime(25943): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265)
12-28 17:30:07.696: E/AndroidRuntime(25943): at android.os.Handler.dispatchMessage(Handler.java:102)
12-28 17:30:07.696: E/AndroidRuntime(25943): at android.os.Looper.loop(Looper.java:136)
12-28 17:30:07.696: E/AndroidRuntime(25943): at android.app.ActivityThread.main(ActivityThread.java:5146)
12-28 17:30:07.696: E/AndroidRuntime(25943): at java.lang.reflect.Method.invokeNative(Native Method)
12-28 17:30:07.696: E/AndroidRuntime(25943): at java.lang.reflect.Method.invoke(Method.java:515)
12-28 17:30:07.696: E/AndroidRuntime(25943): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:732)
12-28 17:30:07.696: E/AndroidRuntime(25943): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:566)
12-28 17:30:07.696: E/AndroidRuntime(25943): at dalvik.system.NativeStart.main(Native Method)
12-28 17:30:07.696: E/AndroidRuntime(25943): Caused by: java.lang.RuntimeException: Could not find test class. Class: com.io7m.examples.m2e_example.tests.AllTests
12-28 17:30:07.696: E/AndroidRuntime(25943): at android.test.AndroidTestRunner.runFailed(AndroidTestRunner.java:255)
12-28 17:30:07.696: E/AndroidRuntime(25943): at android.test.AndroidTestRunner.loadTestClass(AndroidTestRunner.java:89)
12-28 17:30:07.696: E/AndroidRuntime(25943): at android.test.AndroidTestRunner.setTestClassName(AndroidTestRunner.java:50)
12-28 17:30:07.696: E/AndroidRuntime(25943): at android.test.suitebuilder.TestSuiteBuilder.addTestClassByName(TestSuiteBuilder.java:80)
12-28 17:30:07.696: E/AndroidRuntime(25943): at android.test.InstrumentationTestRunner.parseTestClass(InstrumentationTestRunner.java:443)
12-28 17:30:07.696: E/AndroidRuntime(25943): at android.test.InstrumentationTestRunner.parseTestClasses(InstrumentationTestRunner.java:424)
12-28 17:30:07.696: E/AndroidRuntime(25943): at android.test.InstrumentationTestRunner.onCreate(InstrumentationTestRunner.java:370)
12-28 17:30:07.696: E/AndroidRuntime(25943): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4464)
12-28 17:30:07.696: E/AndroidRuntime(25943): ... 10 more

So, for some reason, the class isn't found (not even the test class, let alone
the classes from core).

If I look in tests/target/classes.dex, I see:

$ strings tests/target/classes.dex
<init>
AllTests.java
BuildConfig.java
DEBUG
Hello
HelloTest.java
&Landroid/test/InstrumentationTestCase;
,Landroid/test/suitebuilder/TestSuiteBuilder;
(Lcom/io7m/examples/m2e_example/SayHello;
.Lcom/io7m/examples/m2e_example/tests/AllTests;
1Lcom/io7m/examples/m2e_example/tests/BuildConfig;
/Lcom/io7m/examples/m2e_example/tests/HelloTest;
,Lcom/io7m/examples/m2e_example/tests/R$attr;
0Lcom/io7m/examples/m2e_example/tests/R$drawable;
'Lcom/io7m/examples/m2e_example/tests/R;
"Ldalvik/annotation/EnclosingClass;
Ldalvik/annotation/InnerClass;
!Ldalvik/annotation/MemberClasses;
Ljava/io/PrintStream;
Ljava/lang/Class;
Ljava/lang/Object;
Ljava/lang/String;
Ljava/lang/System;
Ljunit/framework/Test;
Ljunit/framework/TestSuite;
R.java
SayHello.java
accessFlags
attr
build
drawable
ic_launcher
includeAllPackagesUnderHere
name
println
speak
suite
testHello
this
value

However, if I look in tests/bin/classes.dex, I see:

$ strings tests/bin/classes.dex
<init>
BuildConfig.java
CLASS
CONSTRUCTOR
DEBUG
FIELD
LOCAL_VARIABLE
!Landroid/annotation/SuppressLint;
Landroid/annotation/TargetApi;
1Lcom/io7m/examples/m2e_example/tests/BuildConfig;
,Lcom/io7m/examples/m2e_example/tests/R$attr;
0Lcom/io7m/examples/m2e_example/tests/R$drawable;
'Lcom/io7m/examples/m2e_example/tests/R;
"Ldalvik/annotation/EnclosingClass;
Ldalvik/annotation/InnerClass;
!Ldalvik/annotation/MemberClasses;
Ljava/lang/Object;
!Ljava/lang/annotation/Annotation;
"Ljava/lang/annotation/ElementType;
Ljava/lang/annotation/Retention;
&Ljava/lang/annotation/RetentionPolicy;
Ljava/lang/annotation/Target;
METHOD
PARAMETER
R.java
SuppressLint.java
TYPE
TargetApi.java
[Ljava/lang/String;
accessFlags
attr
drawable
ic_launcher
name
this
value

I assume tests/bin/classes.dex is the one that's actually being uploaded to the device.

I'm not exactly sure what's going on here. It's as if the classes.dex produced by Eclipse
doesn't contain any of the project code, or any of the project's dependencies.

What am I doing wrong?

M

Ricardo Gladwell

unread,
Dec 30, 2014, 12:51:39 PM12/30/14
to maven-androi...@googlegroups.com
This looks as though it might be a bug in m2e-android, I've opened an issue here to track this:

https://github.com/rgladwell/m2e-android/issues/300

Please subscribe to stay updated.

Regards...

-- Ricardo Gladwell
http://gladwell.me
Reply all
Reply to author
Forward
0 new messages