liudonghua123 / android-test-kit

Automatically exported from code.google.com/p/android-test-kit
0 stars 0 forks source link

Using GoogleInstrumentationTestRunner in multidex project #106

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. enable multidex - http://developer.android.com/tools/building/multidex.html
2. run a ActivityInstrumentationTestCase2 with GoogleInstrumentationTestRunner

What is the expected output? What do you see instead?

Expect tests to run. 
Actual: Instrumentation run failed due to 'java.lang.NoClassDefFoundError'

What version of the product are you using? On what operating system?

espresso-1.1 on osx

Please provide any additional information below.

MultiDex support for tests requires the MultiDexTestRunner. Espresso requires 
the GoogleInstrumentationTestRunner. Do I need an implementation that merges 
both?

Original issue reported on code.google.com by jem.maw...@gmail.com on 5 Dec 2014 at 4:57

GoogleCodeExporter commented 9 years ago
The MultiDexTestRunner thing is not really a problem. It only has a single line 
to call `MultiDex.install(getTargetContext())` - so I can just extend 
GoogleInstrumentationTestRunner and add that line to onCreate.

However, the NoClassDefException still exists. Logcat provides more info:

E/AndroidRuntime﹕ FATAL EXCEPTION: main
    java.lang.NoClassDefFoundError: com.google.android.apps.common.testing.testrunner.UsageTracker$NoOpUsageTracker
            at com.google.android.apps.common.testing.testrunner.UsageTrackerRegistry.<clinit>(UsageTrackerRegistry.java:13)
            at com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner.onCreate(GoogleInstrumentationTestRunner.java:106)

Original comment by jem.maw...@gmail.com on 5 Dec 2014 at 6:14

GoogleCodeExporter commented 9 years ago
I'm also running into this error. And i'm using espresso-2.0 on osx

Original comment by namk...@gmail.com on 7 Jan 2015 at 8:26

GoogleCodeExporter commented 9 years ago
I'm using Espresso 2 as well. I implemented a custom runner that extends the 
new AndroidJUnitRunner and calls MultiDex.install(getTargetContext()) in 
onCreate(Bundle args). Further; I'm using a custom Application class that 
extends MultiDexApplication in my app.

Logcat output:
dalvikvm﹕ Class resolved by unexpected DEX: 
[Landroid/support/multidex/MultiDexApplication;] 
/dalvikvm﹕ (Lde/epost/abcapp/ABCApplication; had used a different 
Landroid/support/multidex/MultiDexApplication; during pre-verification)
dalvikvm﹕ Unable to resolve superclass of Labcapp/ABCApplication; (225)
/dalvikvm﹕ Link of class 'Labcapp/ABCApplication;' failed
AndroidRuntime﹕ FATAL EXCEPTION: main
Process: abcapp, PID: 2676
java.lang.IllegalAccessError: Class ref in pre-verified class resolved to 
unexpected implementation

Original comment by MufuSc...@gmail.com on 9 Jan 2015 at 2:06

GoogleCodeExporter commented 9 years ago
solution? could fix this issue, but finally got stuck on:
junit.framework.AssertionFailedError: Exception in constructor: 
…NoClassDefFoundError
…

Original comment by to.mikek...@gmail.com on 12 Feb 2015 at 12:54

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Hi, the problem with "java.lang.IllegalAccessError: Class ref in pre-verified 
class resolved to unexpected implementation" is usually due to duplicate 
dependencies.

I have the current configuration that is "running" at least:
   ... 
   androidTestCompile('com.android.support.test.espresso:espresso-core:2.0') { 
        exclude group: 'com.google.guava' 
    }
    androidTestCompile('com.android.support.test:testing-support-lib:0.1') { 
        exclude group: 'com.google.guava' 
    }
    testingCompile ('com.android.support.test.espresso:espresso-contrib:2.0') {
        exclude group: 'com.google.guava'
        exclude group: 'javax.inject'
    }

Original comment by marba...@gmail.com on 26 Feb 2015 at 4:26

GoogleCodeExporter commented 9 years ago
The following question in SO ( 
http://stackoverflow.com/questions/25434099/running-tests-using-gradle-or-inside
-android-studio-result-in-noclassdeffounderr) addresses this issue. The 
accepted answer helped a lot having a working version with espresso 2 using 
multidex for api14+.

Original comment by marba...@gmail.com on 26 Feb 2015 at 8:25

GoogleCodeExporter commented 9 years ago
GITR is deprectated in favor of AndroidJunitRunner. If you're still having 
issues with AJUR, please open a new bug.

Original comment by vale...@google.com on 30 Mar 2015 at 8:59