Android的测试java.lang.NoClassDefFoundError的错误,由于巨星,Android的 [英] Android Testing java.lang.NoClassDefFoundError Error due to Fest-Android

查看:340
本文介绍了Android的测试java.lang.NoClassDefFoundError的错误,由于巨星,Android的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在实施巨星为Android到我的项目,但我似乎遇到了依赖问题。如果我跑我的测试,而不包括巨星库,测试将照常运行。有一次,我在巨星库中添加则测试不再运行。一个例外是,而不是抛出。

I'm currently implementing Fest for Android into my project but I seem to be running into a dependency issue. If I run my tests without the Fest library included, the tests will run as normal. Once I add in the Fest library then the tests no longer run. An exception is thrown instead.

我的项目使用下面的依赖关系:

My project uses the following dependencies:

compile files('libs/robotium-solo-5.1.jar')
androidTestCompile 'com.squareup:fest-android:1.0.8'
androidTestCompile 'com.google.code.gson:gson:2.2.4'
androidTestCompile 'com.jayway.android.robotium:robotium-solo:5.1'
androidTestCompile 'com.google.mockwebserver:mockwebserver:20130706'
androidTestCompile 'com.google.dexmaker:dexmaker:1.0'
androidTestCompile('com.google.dexmaker:dexmaker-mockito:1.0') {
    exclude module: 'hamcrest-core'
    exclude module: 'objenesis'
    exclude module: 'mockito-core'
}
androidTestCompile 'org.mockito:mockito-all:+'

我试过不包括我下面列出的巨星Android的依赖,但对测试的运行没有影响。

I've tried excluding the Fest Android dependencies that I've listed below but it has no effect on the running of the tests.

androidTestCompile ('com.squareup:fest-android:1.0.8') {
    exclude group: 'com.google.android', module: 'android'
    exclude group: 'com.google.android', module: 'support-v4'
    exclude group: 'org.easytesting', module: 'fest-assert-core'
}

这是包括当测试与巨星库运行发生异常。

This is the exception that is occurring when the tests are run with the Fest library included.

junit.framework.AssertionFailedError: Exception in constructor: testClickActionBarItems (java.lang.NoClassDefFoundError: com.example.android.activities.SectionsActivity
at com.example.android.test.activities.SectionsEspressoTests.<init>(SectionsEspressoTests.java:21)
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
at junit.runner.BaseTestRunner.getTest(BaseTestRunner.java:118)
at android.test.AndroidTestRunner.getTest(AndroidTestRunner.java:148)
at android.test.AndroidTestRunner.setTestClassName(AndroidTestRunner.java:56)
at android.test.suitebuilder.TestSuiteBuilder.addTestClassByName(TestSuiteBuilder.java:80)
at android.test.InstrumentationTestRunner.parseTestClass(InstrumentationTestRunner.java:444)
at android.test.InstrumentationTestRunner.parseTestClasses(InstrumentationTestRunner.java:425)
at android.test.InstrumentationTestRunner.onCreate(InstrumentationTestRunner.java:370)
at com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner.onCreate(GoogleInstrumentationTestRunner.java:114)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4382)
at android.app.ActivityThread.access$1300(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1294)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5041)
at java.lang.reflect.Method.invokeNative(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:190)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:175)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:555)
at com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner.onStart(GoogleInstrumentationTestRunner.java:167)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1661)

任何帮助或建议将不胜AP preciated。

Any help or suggestions would be greatly appreciated.

推荐答案

您有两个问题在这里:


  1. 您正在编制robotium的两个版本到您的项目,这样你就可以删除其中的一个。

  1. You are compiling two versions of robotium into your project, so you can remove one of them.

FEST-的Andr​​oid已经支持-V4库的依赖关系,所以你需要排除,就像你不包括hamcrest芯'从'dexmaker-的Mockito'的依赖。你可以看到所有的依赖从 FEST-Android的依赖

FEST-Android already has a dependency of support-v4 library so you will need to exclude that just like you are excluding 'hamcrest-core' from the 'dexmaker-mockito' dependency. You can see all of its dependencies from FEST-Android Dependencies.

我会建议您做如下更改您的依赖关系。

I would recommend that you make the following changes to your dependencies.

// Testing Libraries
androidTestCompile('com.squareup:fest-android:1.0.8') {
    exclude module: 'support-v4'
}
androidTestCompile('com.google.code.gson:gson:2.2.4')
androidTestCompile('com.jayway.android.robotium:robotium-solo:5.1')
androidTestCompile('com.google.mockwebserver:mockwebserver:20130706')
androidTestCompile('com.google.dexmaker:dexmaker:1.0')
androidTestCompile('com.google.dexmaker:dexmaker-mockito:1.0') {
    exclude module: 'hamcrest-core'
    exclude module: 'objenesis'
    exclude module: 'mockito-core'
}
androidTestCompile('org.mockito:mockito-all:+')

正如你可以看到我已经删除,你有额外的robotium依赖,我也排除了模块的的支持-V4的。这应该可以有你回来在任何时间运行测试! :-D

As you can see I have removed the extra robotium dependency that you had and I have also excluded the module 'support-v4'. Hopefully this should have you back running tests in no time! :-D

这篇关于Android的测试java.lang.NoClassDefFoundError的错误,由于巨星,Android的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆