开发者

Android JUnit Tests failing with java.lang.VerifyError

开发者 https://www.devze.com 2023-02-20 01:24 出处:网络
Aloha, I\'ve been following the guidelines here: http://developer.android.com/resources/tutorials/testing/helloandroid_test.html

Aloha,

I've been following the guidelines here:

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

To create some simple test cases for a new Android project. The first few test cases were working fine, but now I am not able to get any tests to run. Here is an example of the output I am getting:

    [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

The test case is very simple:

/**
 * 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);

is a static method. I've removed all the code from it so all it does, literally is return null. The test always fails with the java.lang.VerifyError.

This is under Android 2.3 using the Android JUnit Test runner in Eclipse.

Any ideas? I've tried recreating the test project and all sorts of permutations of code modifications.

Thanks in advance!

EDIT (!): Logcat output:

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

I am using Maven for class dependencies. Here are the libraries I am including via 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/re开发者_Go百科pository/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


Are you using any external jars? This seems to be a common source of java.lang.VerifyError in my experience.

As this answer suggests you may need to recompile them or run them through dx so that they contain dalvik bytecode.

Edit - I haven't dealt with this myself, and I'm not sure about the maven way to do this, but at some point I think you need to use dx on your jars:

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

If possible you might try doing this manually on your jars to see if that's actually the problem, and then try to integrate that into your maven build afterwards.


What I ended up doing is simply removing the code that was using these libraries. In most cases it was pretty trivial to do so.


If you are using external libraries in your main project you should export them to your tests.


Upgrading my build tool to 21.1.2 from 19.1.0 fixed my Tests failures with java.lang.VerifyError

apply plugin: 'android'

android {
    compileSdkVersion 19
    buildToolsVersion '21.1.2'
    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 19
        versionCode 1
        versionName "2.0"
        testInstrumentationRunner "android.test.InstrumentationTestRunner"
    }

    buildTypes {
        release {
            minifyEnabled true
            debuggable false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
        debug {
            debuggable true
            minifyEnabled false
            multiDexEnabled false
            testCoverageEnabled = true
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
}
0

精彩评论

暂无评论...
验证码 换一张
取 消