静态类无法加载到espresso单元测试中

时间:2014-12-18 18:04:49

标签: java android unit-testing android-gradle android-espresso

问题:

您好,我正在尝试为Android运行espresso单元测试,我现在面临的一个问题是静态方法是给我一个没有找到类的错误,请帮忙。

代码:

public Fragment buildFragment(int id){
    switch(id){
        case R.id.fragment_landing:
            return LandingFragment.newInstance();
        case R.id.fragment_splash:
            return SplashScreenFragment.newInstance();
        case R.id.fragment_join:
            return JoinFragment.newInstance();
        case R.id.fragment_login:
            return LoginFragment.newInstance();
        case R.id.fragment_reset_password:
            return ResetPasswordFragment.newInstance();
        case R.id.fragment_search:
            return CompetitionFragment.newInstance();
        case R.id.fragment_competition:
            return CompetitionFragment.newInstance();
        default:
            return SplashScreenFragment.newInstance();
    }
}

堆栈追踪:

java.lang.NoClassDefFoundError: co/metoo/sashimi/views/fragments/LandingFragment
        at co.mitoo.sashimi.utils.FragmentFactory.buildFragment(FragmentFactory.java:25)
        at     
co.mitoo.sashimi.views.activities.MetooActivity.changeFragment(MetooActivity.java:125)
        at co.mitoo.sashimi.views.activities.MetooActivity$1.run(MetooActivity.java:39)
        at android.os.Handler.handleCallback(Handler.java:733)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:136)
        at android.app.ActivityThread.main(ActivityThread.java:5001)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
        at dalvik.system.NativeStart.main(Native Method)

Caused by: java.lang.IllegalAccessError: Class ref in pre-verified class resolved to   
unexpected implementation
        at dalvik.system.DexFile.defineClassNative(Native Method)
        at dalvik.system.DexFile.defineClass(DexFile.java:222)
        at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:215)
        at dalvik.system.DexPathList.findClass(DexPathList.java:322)
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:54)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:457) 
    at co.mitoo.sashimi.utils.FragmentFactory.buildFragment(FragmentFactory.java:25)

摇篮

依赖项{

// ================== LIBRARIES ======================
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile fileTree(dir: 'libs', include: ['*.jar'])

//Tests And Mocks
androidTestCompile('com.jakewharton.espresso:espresso:1.1-r3'){
    exclude group:'com.android.support', module:'support-v4'
}

androidTestCompile('org.mockito:mockito-core:1.9.5+'){
    exclude group: 'org.hamcrest'
}

androidTestCompile('junit:junit-dep:4.10'){
    exclude group: 'org.hamcrest'
}

androidTestCompile('com.google.dexmaker:dexmaker-mockito:1.0'){
    exclude group: 'org.hamcrest'
}

androidTestCompile('com.android.support:support-v4:+')
androidTestCompile('com.squareup.picasso:picasso:2.3.2')
androidTestCompile('com.nineoldandroids:library:2.4.0')
androidTestCompile('com.daimajia.slider:library:1.1.2@aar')

环境:

Android 1.0.1 Gradle 1.00

0 个答案:

没有答案