gpt4 book ai didi

Android JUnit 测试因 java.lang.VerifyError 失败

转载 作者:太空狗 更新时间:2023-10-29 14:32:14 24 4
gpt4 key购买 nike

你好,

我一直遵循这里的指南:

http://developer.android.com/resources/tutorials/testing/helloandroid_test.html

为新的 Android 项目创建一些简单的测试用例。前几个测试用例运行良好,但现在我无法运行任何测试。这是我得到的输出示例:

    [2011-03-25 10:05:01 - application-tests] Android Launch!
[2011-03-25 10:05:01 - application-tests] adb is running normally.
[2011-03-25 10:05:01 - application-tests] Performing android.test.InstrumentationTestRunner JUnit launch
[2011-03-25 10:05:01 - application-tests] Automatic Target Mode: using existing emulator 'emulator-5554' running compatible AVD 'GalaxyTabRunning2.3'
[2011-03-25 10:05:02 - application-tests] Application already deployed. No need to reinstall.
[2011-03-25 10:05:02 - application-tests] Project dependency found, installing: application
[2011-03-25 10:05:03 - application] Application already deployed. No need to reinstall.
[2011-03-25 10:05:03 - application-tests] Launching instrumentation android.test.InstrumentationTestRunner on device emulator-5554
[2011-03-25 10:05:03 - application-tests] Collecting test information
[2011-03-25 10:05:06 - application-tests] Test run failed: java.lang.VerifyError

测试用例很简单:

/**
* Test case to test a null input parameter to the decode method.
*
*/
public void testNullInputPerformCrcDecoding()
{
try
{
AppProtocolDecoder.performCrcDecoding(null);
fail("Expected IllegalArgumentException to be thrown...");
}
catch (IllegalArgumentException expected)
{
assertTrue(expected instanceof IllegalArgumentException);
}
catch (ProtocolException ve)
{
fail("Unexpected VisiProtocolException occured: " + ve);
}
}

AppProtocolDecoder.performCrcDecoding(null);

是一个静态方法。我已经删除了它的所有代码,所以它所做的一切,字面意思是返回 null。测试总是因 java.lang.VerifyError 而失败。

这是在 Android 2.3 下使用 Eclipse 中的 Android JUnit 测试运行器。

有什么想法吗?我已经尝试重新创建测试项目和各种代码修改排列。

提前致谢!

编辑(!):Logcat 输出:

D/AndroidRuntime(  919): Shutting down VM
W/dalvikvm( 919): threadid=1: thread exiting with uncaught exception (group=0x40015560)
E/AndroidRuntime( 919): FATAL EXCEPTION: main
E/AndroidRuntime( 919): java.lang.VerifyError: com.company.h1s.androidserver.test.protocol.AppProtocolDecoderTest
E/AndroidRuntime( 919): at java.lang.Class.getDeclaredConstructors(Native Method)
E/AndroidRuntime( 919): at java.lang.Class.getConstructors(Class.java:490)
E/AndroidRuntime( 919): at android.test.suitebuilder.TestGrouping$TestCasePredicate.hasValidConstructor(TestGrouping.java:226)
E/AndroidRuntime( 919): at android.test.suitebuilder.TestGrouping$TestCasePredicate.apply(TestGrouping.java:215)
E/AndroidRuntime( 919): at android.test.suitebuilder.TestGrouping$TestCasePredicate.apply(TestGrouping.java:211)
E/AndroidRuntime( 919): at android.test.suitebuilder.TestGrouping.select(TestGrouping.java:170)
E/AndroidRuntime( 919): at android.test.suitebuilder.TestGrouping.selectTestClasses(TestGrouping.java:160)
E/AndroidRuntime( 919): at android.test.suitebuilder.TestGrouping.testCaseClassesInPackage(TestGrouping.java:154)
E/AndroidRuntime( 919): at android.test.suitebuilder.TestGrouping.addPackagesRecursive(TestGrouping.java:115)
E/AndroidRuntime( 919): at android.test.suitebuilder.TestSuiteBuilder.includePackages(TestSuiteBuilder.java:103)
E/AndroidRuntime( 919): at android.test.InstrumentationTestRunner.onCreate(InstrumentationTestRunner.java:360)
E/AndroidRuntime( 919): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3210)
E/AndroidRuntime( 919): at android.app.ActivityThread.access$2200(ActivityThread.java:117)
E/AndroidRuntime( 919): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:966)
E/AndroidRuntime( 919): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 919): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 919): at android.app.ActivityThread.main(ActivityThread.java:3647)
E/AndroidRuntime( 919): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 919): at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime( 919): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
E/AndroidRuntime( 919): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
E/AndroidRuntime( 919): at dalvik.system.NativeStart.main(Native Method)
W/ActivityManager( 61): Error in app com.company.h1s.androidserver running instrumentation ComponentInfo{com.company.h1s.androidserver.test/android.test.InstrumentationTestRunner}:
W/ActivityManager( 61): java.lang.VerifyError
W/ActivityManager( 61): java.lang.VerifyError: com.company.h1s.androidserver.test.protocol.AppProtocolDecoderTest
I/ActivityManager( 61): Force stopping package com.company.h1s.androidserver uid=10031
I/Process ( 61): Sending signal. PID: 919 SIG: 9
D/AndroidRuntime( 911): Shutting down VM

我正在使用 Maven 来处理类依赖项。以下是我通过 Maven 包含的库:

/.m2/repository/com/google/android/android/2.2.1/android-2.2.1.jar
/.m2/repository/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar
/.m2/repository/org/apache/httpcomponents/httpclient/4.0.1/httpclient-4.0.1.jar
/.m2/repository/org/apache/httpcomponents/httpcore/4.0.1/httpcore-4.0.1.jar
/.m2/repository/commons-codec/commons-codec/1.3/commons-codec-1.3.jar
/.m2/repository/org/khronos/opengl-api/gl1.1-android-2.1_r1/opengl-api-gl1.1-android-2.1_r1.jar
/.m2/repository/xerces/xmlParserAPIs/2.6.2/xmlParserAPIs-2.6.2.jar
/.m2/repository/xpp3/xpp3/1.1.4c/xpp3-1.1.4c.jar
/.m2/repository/org/json/json/20080701/json-20080701.jar
/.m2/repository/org/slf4j/slf4j-android/1.6.1-RC1/slf4j-android-1.6.1-RC1.jar
/.m2/repository/org/slf4j/log4j-over-slf4j/1.6.1/log4j-over-slf4j-1.6.1.jar
/.m2/repository/org/slf4j/slf4j-api/1.6.1/slf4j-api-1.6.1.jar
/.m2/repository/org/apache/mina/mina-core/2.0.0/mina-core-2.0.0.jar
/.m2/repository/com/company/app-common/1.0-SNAPSHOT/app-common-1.0-SNAPSHOT.jar
/.m2/repository/commons-lang/commons-lang/2.4/commons-lang-2.4.jar
/.m2/repository/com/company/app-data/1.0-SNAPSHOT/app-data-1.0-SNAPSHOT.jar
/.m2/repository/org/springframework/spring/2.5.6/spring-2.5.6.jar

最佳答案

您是否使用任何外部 jar ?根据我的经验,这似乎是 java.lang.VerifyError 的常见来源。

作为this answer建议您可能需要重新编译它们或通过 dx 运行它们,以便它们包含 dalvik 字节码。

编辑 - 我自己还没有处理过这个问题,我不确定执行此操作的 maven 方法,但在某些时候我认为你需要使用 dx 在你的 jar 上:

dx --dex --output=some.dex.jar some.jar

如果可能,您可以尝试在您的 jars 上手动执行此操作,看看这是否真的是问题所在,然后尝试将其集成到您的 maven 构建中。

关于Android JUnit 测试因 java.lang.VerifyError 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5437595/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com