阿罗哈,
我一直在遵循这些指南:
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 Test runner。
有什么想法吗?我已经尝试重新创建测试项目和各种代码修改的排列。
提前致谢!
编辑(!):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
答案 0 :(得分:1)
你在使用任何外部罐子吗?根据我的经验,这似乎是java.lang.VerifyError的常见来源。
由于this answer建议您可能需要重新编译它们或通过dx运行它们以便它们包含dalvik字节码。
编辑 - 我自己没有处理过这个问题,而且我不确定这样做的方法,但在某些时候我认为你需要使用dx
在你的罐子里:
dx --dex --output=some.dex.jar some.jar
如果可能的话,您可以尝试在罐子上手动执行此操作,看看是否真的出现问题,然后尝试将其集成到您的maven构建中。
答案 1 :(得分:0)
如果您在主项目中使用外部库,则应将它们导出到测试中。
答案 2 :(得分:0)
我最终做的只是删除使用这些库的代码。在大多数情况下,这样做非常简单。
答案 3 :(得分:0)
将我的构建工具从import requests
s = requests.Session()
r = s.get('https://login.live.com',verify=False)
r = s.post('https://login.live.com', auth=('user', 'pass'),verify=False)
print r.status_code
print r.text
升级到21.1.2
,并使用19.1.0
修复了我的测试失败
java.lang.VerifyError