我有一个使用robolectric进行数百个单元测试的应用程序,在我的应用程序Parse.initialize(this, "", "");
中添加Parse SDK之后,所有测试都开始失败并出现错误causing java.lang.VerifyError: Bad type on operand stack
,尽管应用程序没有问题。
编辑:我知道在没有Parse的情况下运行测试的变通办法。我希望能够运行使用Parse框架的测试。
完整的堆栈跟踪如下所示。
/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/bin/java -ea -Didea.launcher.port=7532 "-Didea.launcher.bin.path=/Applications/Android Studio.app/Contents/bin" -Didea.junit.sm_runner -Dfile.encoding=UTF-8 -classpath "/Applications/Android Studio.app/Contents/lib/idea_rt.jar:/Applications/Android Studio.app/Contents/plugins/junit/lib/junit-rt.jar:/Users/guilhermecastro/Library/Android/sdk/platforms/android-23/data/res:/Users/guilhermecastro/Documents/appprova-android/app/build/intermediates/classes/test/enem/debug:/Users/guilhermecastro/Documents/appprova-android/app/build/intermediates/classes/enem/debug:/Users/guilhermecastro/.gradle/caches/modules-2/files-2.1/org.robolectric/robolectric-annotations/3.1-SNAPSHOT/b766a056ea427a742dd79506bdbb63252393a1cf/robolectric-annotations-3.1-SNAPSHOT.jar:/Users/guilhermecastro/Documents/appprova-android/app/build/intermediates/exploded-aar/com.google.android.gms/play-services-auth/8.4.0/jars/classes.jar:/Users/guilhermecastro/Documents/appprova-android/app/build/intermediates/exploded-aar/com.google.android.gms/play-services-auth/8.4.0/res:/Users/guilhermecastro/.gradle/caches/modules-2/files-2.1/org.hamcrest/hamcrest-library/1.3/4785a3c21320980282f9f33d0d1264a69040538f/hamcrest-library-1.3.jar:/Users/guilhermecastro/.gradle/caches/modules-2/files-2.1/org.ow2.asm/asm-commons/5.0.1/7b7147a390a93a14d2edfdcf3f7b0e87a0939c3e/asm-commons-5.0.1.jar:/Users/guilhermecastro/.gradle/caches/modules-2/files-2.1/com.google.android.apps.common.testing.accessibility.framework/accessibility-test-framework/2.1/c2d6267c3ad0435ddf9e27a94a0e0af4ca3fdfbb/accessibility-test-framework-2.1.jar:/Users/guilhermecastro/Documents/appprova-android/app/build/intermediates/exploded-aar/com.google.android.gms/play-services-base/8.4.0/jars/classes.jar:/Users/guilhermecastro/Documents/appprova-android/app/build/intermediates/exploded-aar/com.google.android.gms/play-services-base/8.4.0/res:/Users/guilhermecastro/Documents/appprova-android/app/build/intermediates/exploded-aar/com.google.android.gms/play-services-measurement/8.4.0/jars/classes.jar:/Users/guilhermecastro/Documents/appprova-android/app/build/intermediates/exploded-aar/com.google.android.gms/play-services-measurement/8.4.0/res:/Users/guilhermecastro/.gradle/caches/modules-2/files-2.1/org.ow2.asm/asm/5.0.1/2fd56467a018aafe6ec6a73ccba520be4a7e1565/asm-5.0.1.jar:/Users/guilhermecastro/Documents/appprova-android/app/build/intermediates/exploded-aar/com.android.support/recyclerview-v7/23.3.0/jars/classes.jar:/Users/guilhermecastro/Documents/appprova-android/app/build/intermediates/exploded-aar/com.android.support/recyclerview-v7/23.3.0/res:/Users/guilhermecastro/.gradle/caches/modules-2/files-2.1/org.androidannotations/rest-spring-api/4.0-SNAPSHOT/437f51d0168f1fc7276228c632f40a580e4cd032/rest-spring-api-4.0-SNAPSHOT.jar:/Users/guilhermecastro/Documents/appprova-android/app/build/intermediates/exploded-aar/com.google.android.gms/play-services-vision/8.4.0/jars/classes.jar:/Users/guilhermecastro/Documents/appprova-android/app/build/intermediates/exploded-aar/com.google.android.gms/play-services-vision/8.4.0/res:/Users/guilhermecastro/.gradle/caches/modules-2/files-2.1/com.jayway.awaitility/awaitility/1.7.0/e4fa7955cab67d880e4868a0795cce3498ea7bf2/awaitility-1.7.0.jar:/Users/guilhermecastro/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.core/jackson-annotations/2.6.0/a0990e2e812ac6639b6ce955c91b13228500476e/jackson-annotations-2.6.0.jar:/Users/guilhermecastro/.gradle/caches/modules-2/files-2.1/org.robolectric/shadows-core/3.1-SNAPSHOT/b82376c4080f576f9ae7dd8d5e69d4e9ad015e08/shadows-core-3.1-SNAPSHOT.jar:/Users/guilhermecastro/Documents/appprova-android/app/build/intermediates/exploded-aar/labelledspinner-release/res:/Users/guilhermecastro/Documents/appprova-android/app/build/intermediates/exploded-aar/labelledspinner-release/jars/classes.jar:/Users/guilhermecastro/.gradle/caches/modules-2/files-2.1/org.robolectric/robolectric/3.1-SNAPSHOT/6473b51558001a1f38d905947eff5108e90280cf/robolectric-3.1-SNAPSHOT.jar:/Users/guilhermecastro/.gradle/caches/modules-2/files-2.1/com.parse.bolts/bolts-android/1.2.0/6ee2953ccf51ce72b6d548c30c4633b99eb4f9dd/bolts-android-1.2.0.jar:/Users/guilhermecastro/Library/Android/sdk/extras/android/m2repository/com/android/support/support-annotations/23.3.0/support-annotations-23.3.0.jar:/Users/guilhermecastro/Documents/appprova-android/app/build/intermediates/exploded-aar/com.android.support/support-vector-drawable/23.3.0/jars/classes.jar:/Users/guilhermecastro/Documents/appprova-android/app/build/intermediates/exploded-aar/com.android.support/support-vector-drawable/23.3.0/res:/Users/guilhermecastro/Documents/appprova-android/app/build/intermediates/exploded-aar/com.android.support/animated-vector-drawable/23.3.0/jars/classes.jar:/Users/guilhermecastro/Documents/appprova-android/app/build/intermediates/exploded-aar/com.android.support/animated-vector-drawable/23.3.0/res:/Users/guilhermecastro/.gradle/caches/modules-2/files-2.1/xmlpull/xmlpull/1.1.3.1/2b8e230d2ab644e4ecaa94db7cdedbc40c805dfa/xmlpull-1.1.3.1.jar:/Users/guilhermecastro/.gradle/caches/modules-2/files-2.1/com.parse/parse-android/1.13.0/58a7d54b6a4f28be11f0cecec93097eddf473e6f/parse-android-1.13.0.jar:/Users/guilhermecastro/Documents/appprova-android/app/build/intermediates/exploded-aar/com.android.support/appcompat-v7/23.3.0/res:/Users/guilhermecastro/Documents/appprova-android/app/build/intermediates/exploded-aar/com.android.support/appcompat-v7/23.3.0/jars/classes.jar:/Users/guilhermecastro/.gradle/caches/modules-2/files-2.1/commons-codec/commons-codec/1.3/fd32786786e2adb664d5ecc965da47629dca14ba/commons-codec-1.3.jar:/Users/guilhermecastro/.gradle/caches/modules-2/files-2.1/com.ibm.icu/icu4j/53.1/786d9055d4ca8c1aab4a7d4ac8283f973fd7e41f/icu4j-53.1.jar:/Applications/Android Studio.app/Contents/gradle/m2repository/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar:/Users/guilhermecastro/Documents/appprova-android/app/build/intermediates/exploded-aar/com.crashlytics.sdk.android/beta/1.1.4/jars/classes.jar:/Users/guilhermecastro/Documents/appprova-android/app/build/intermediates/exploded-aar/com.crashlytics.sdk.android/beta/1.1.4/res:/Users/guilhermecastro/.gradle/caches/modules-2/files-2.1/cglib/cglib-nodep/3.1/aa83efbd1aedc4f26bdf00e7ea78191483f2c9b3/cglib-nodep-3.1.jar:/Users/guilhermecastro/.gradle/caches/modules-2/files-2.1/com.almworks.sqlite4java/sqlite4java/0.282/745a7e2f35fdbe6336922e0d492c979dbbfa74fb/sqlite4java-0.282.jar:/Users/guilhermecastro/.gradle/caches/modules-2/files-2.1/org.ow2.asm/asm-tree/5.0.1/1b1e6e9d869acd704056d0a4223071a511c619e6/asm-tree-5.0.1.jar:/Users/guilhermecastro/.gradle/caches/modules-2/files-2.1/org.robolectric/shadows-support-v4/3.1-SNAPSHOT/48ece111d7d02dc991f2fa43ca427fb3cda211f0/shadows-support-v4-3.1-SNAPSHOT.jar:/Users/guilhermecastro/Documents/appprova-android/app/build/intermediates/exploded-aar/com.crashlytics.sdk.android/answers/1.3.6/jars/classes.jar:/Users/guilhermecastro/Documents/appprova-android/app/build/intermediates/exploded-aar/com.crashlytics.sdk.android/answers/1.3.6/res:/Users/guilhermecastro/.gradle/caches/modules-2/files-2.1/org.springframework.android/spring-android-core/1.0.1.RELEASE/e68f0e8e4b636ee30c4de58953be38d9b72a5e3b/spring-android-core-1.0.1.RELEASE.jar:/Users/guilhermecastro/.gradle/caches/modules-2/files-2.1/org.apache.maven/maven-ant-tasks/2.1.3/b09be554228d66d208e5fef5266844aacf443abc/maven-ant-tasks-2.1.3.jar:/Users/guilhermecastro/.gradle/caches/modules-2/files-2.1/org.apache.ant/ant/1.8.0/7b456ca6b93900f96e58cc8371f03d90a9c1c8d1/ant-1.8.0.jar:/Users/guilhermecastro/.gradle/caches/modules-2/files-2.1/com.google.guava/guava/19.0-rc2/93e17f60bc524c2610b41c494bb829c11ca89436/guava-19.0-rc2.jar:/Users/guilhermecastro/Documents/appprova-android/app/build/intermediates/exploded-aar/com.mikhaellopez/circularimageview/2.1.1/jars/classes.jar:/Users/guilhermecastro/Documents/appprova-android/app/build/intermediates/exploded-aar/com.mikhaellopez/circularimageview/2.1.1/res:/Users/guilhermecastro/.gradle/caches/modules-2/files-2.1/org.apache.ant/ant-launcher/1.8.0/8b53ba16fa62fb1034da8f1de200ddc407c8381/ant-launcher-1.8.0.jar:/Users/guilhermecastro/.gradle/caches/modules-2/files-2.1/xpp3/xpp3_min/1.1.4c/19d4e90b43059058f6e056f794f0ea4030d60b86/xpp3_min-1.1.4c.jar:/Users/guilhermecastro/.gradle/caches/modules-2/files-2.1/com.parse.bolts/bolts-tasks/1.4.0/d85884acf6810a3bbbecb587f239005cbc846dc4/bolts-tasks-1.4.0.jar:/Users/guilhermecastro/.gradle/caches/modules-2/files-2.1/org.robolectric/robolectric-utils/3.1-SNAPSHOT/b52242aa999e3c7069f9e0ff573bf4ecbc8dec07/robolectric-utils-3.1-SNAPSHOT.jar:/Users/guilhermecastro/.gradle/caches/modules-2/files-2.1/org.androidannotations/androidannotations-api/4.0-SNAPSHOT/6df845decdeef73e5b631cdaa82306a6a03b199b/androidannotations-api-4.0-SNAPSHOT.jar:/Users/guilhermecastro/Documents/appprova-android/app/build/intermediates/exploded-aar/com.google.android.gms/play-services-analytics/8.4.0/res:/Users/guilhermecastro/Documents/appprova-android/app/build/intermediates/exploded-aar/com.google.android.gms/play-services-analytics/8.4.0/jars/classes.jar:/Users/guilhermecastro/.gradle/caches/modules-2/files-2.1/com.thoughtworks.xstream/xstream/1.4.8/520d90f30f36a0d6ba2dc929d980831631ad6a92/xstream-1.4.8.jar:/Users/guilhermecastro/Documents/appprova-android/app/build/intermediates/exploded-aar/com.android.support/support-v4/23.3.0/jars/classes.jar:/Users/guilhermecastro/Documents/appprova-android/app/build/intermediates/exploded-aar/com.android.support/support-v4/23.3.0/res:/Users/guilhermecastro/Documents/appprova-android/app/build/intermediates/exploded-aar/com.android.support/support-v4/23.3.0/jars/libs/internal_impl-23.3.0.jar:/Users/guilhermecastro/.gradle/caches/modules-2/files-2.1/org.mockito/mockito-all/1.10.19/539df70269cc254a58cccc5d8e43286b4a73bf30/mockito-all-1.10.19.jar:/Users/guilhermecastro/.gradle/caches/modules-2/files-2.1/org.ow2.asm/asm-util/5.0.1/7c8caddfbd0b2d7b844f8fcc75175b9cb9cf4724/asm-util-5.0.1.jar:/Users/guilhermecastro/.gradle/caches/modules-2/files-2.1/org.bouncycastle/bcprov-jdk16/1.46/ce091790943599535cbb4de8ede84535b0c1260c/bcprov-jdk16-1.46.jar:/Users/guilhermecastro/.gradle/caches/modules-2/files-2.1/com.github.bumptech.glide/glide/3.7.0/9e9eeaf9948ee4d6c3ab354e8dc14368f16994a4/glide-3.7.0.jar:/Users/guilhermecastro/.gradle/caches/modules-2/files-2.1/org.objenesis/objenesis/2.1/87c0ea803b69252868d09308b4618f766f135a96/objenesis-2.1.jar:/Users/guilhermecastro/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpclient/4.0.3/fcacc35075d9c3114da4c4122b42d78786135c90/httpclient-4.0.3.jar:/Users/guilhermecastro/Documents/appprova-android/app/build/intermediates/exploded-aar/io.fabric.sdk.android/fabric/1.3.10/res:/Users/guilhermecastro/Documents/appprova-android/app/build/intermediates/exploded-aar/io.fabric.sdk.android/fabric/1.3.10/jars/classes.jar:/Users/guilhermecastro/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.core/jackson-core/2.6.3/142ce64dcd709a4b5f6e7d71305a31d3893d077/jackson-core-2.6.3.jar:/Users/guilhermecastro/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpcore/4.0.1/e813b8722c387b22e1adccf7914729db09bcb4a9/httpcore-4.0.1.jar:/Users/guilhermecastro/Documents/appprova-android/app/build/intermediates/exploded-aar/com.crashlytics.sdk.android/crashlytics/2.5.5/jars/classes.jar:/Users/guilhermecastro/Documents/appprova-android/app/build/intermediates/exploded-aar/com.crashlytics.sdk.android/crashlytics/2.5.5/res:/Users/guilhermecastro/.gradle/caches/modules-2/files-2.1/org.robolectric/robolectric-resources/3.1-SNAPSHOT/945b87482365c347080c5b78fd268f1bd8567bd4/robolectric-resources-3.1-SNAPSHOT.jar:/Users/guilhermecastro/Documents/appprova-android/app/build/intermediates/exploded-aar/com.crashlytics.sdk.android/crashlytics-core/2.3.8/res:/Users/guilhermecastro/Documents/appprova-android/app/build/intermediates/exploded-aar/com.crashlytics.sdk.android/crashlytics-core/2.3.8/jars/classes.jar:/Users/guilhermecastro/.gradle/caches/modules-2/files-2.1/org.springframework.android/spring-android-rest-template/1.0.1.RELEASE/e132d929bd181941f79b0d63edafb8a86ae6fd33/spring-android-rest-template-1.0.1.RELEASE.jar:/Users/guilhermecastro/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.core/jackson-databind/2.6.3/5c4fcae53dd82e2c549b8322d78c6ff47c94c8a8/jackson-databind-2.6.3.jar:/Users/guilhermecastro/Documents/appprova-android/app/build/intermediates/exploded-aar/com.android.support/design/23.3.0/jars/classes.jar:/Users/guilhermecastro/Documents/appprova-android/app/build/intermediates/exploded-aar/com.android.support/design/23.3.0/res:/Users/guilhermecastro/Documents/appprova-android/app/build/intermediates/exploded-aar/com.android.support/cardview-v7/23.3.0/res:/Users/guilhermecastro/Documents/appprova-android/app/build/intermediates/exploded-aar/com.android.support/cardview-v7/23.3.0/jars/classes.jar:/Users/guilhermecastro/.gradle/caches/modules-2/files-2.1/org.ow2.asm/asm-analysis/5.0.1/e286fbee48efacb4e7c175f7948d9d8b2ab52352/asm-analysis-5.0.1.jar:/Users/guilhermecastro/.gradle/caches/modules-2/files-2.1/com.google.protobuf/protobuf-java/2.6.1/d9521f2aecb909835746b7a5facf612af5e890e8/protobuf-java-2.6.1.jar:/Users/guilhermecastro/Documents/appprova-android/app/build/intermediates/exploded-aar/com.facebook.android/facebook-android-sdk/4.6.0/res:/Users/guilhermecastro/Documents/appprova-android/app/build/intermediates/exploded-aar/com.facebook.android/facebook-android-sdk/4.6.0/jars/classes.jar:/Users/guilhermecastro/.gradle/caches/modules-2/files-2.1/org.hamcrest/hamcrest-core/1.3/42a25dc3219429f0e5d060061f71acb49bf010a0/hamcrest-core-1.3.jar:/Users/guilhermecastro/.gradle/caches/modules-2/files-2.1/org.robolectric/shadows-httpclient/3.1-SNAPSHOT/6b20423f62a6afa8c8eaefa7735f13fa7599497c/shadows-httpclient-3.1-SNAPSHOT.jar:/Users/guilhermecastro/.gradle/caches/modules-2/files-2.1/com.ximpleware/vtd-xml/2.11/ee5bcf62c1acf76434ee9f1c67a840bafef72a6d/vtd-xml-2.11.jar:/Users/guilhermecastro/.gradle/caches/modules-2/files-2.1/junit/junit/4.12/2973d150c0dc1fefe998f834810d68f278ea58ec/junit-4.12.jar:/Users/guilhermecastro/Documents/appprova-android/app/build/intermediates/exploded-aar/com.google.android.gms/play-services-basement/8.4.0/res:/Users/guilhermecastro/Documents/appprova-android/app/build/intermediates/exploded-aar/com.google.android.gms/play-services-basement/8.4.0/jars/classes.jar:/Users/guilhermecastro/Documents/appprova-android/app/build/intermediates/sourceFolderJavaResources/test/enem/debug:/Users/guilhermecastro/Documents/appprova-android/app/build/intermediates/sourceFolderJavaResources/enem/debug:/Users/guilhermecastro/Documents/appprova-android/build/generated/mockable-android-23.jar" com.intellij.rt.execution.application.AppMain com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 com.appprova.core.activity.AnswerActivityTest,testWrongAnswer
Exception in thread "pool-3-thread-1" java.lang.VerifyError: Bad type on operand stack
Exception Details:
Location:
com/parse/ParsePinningEventuallyQueue.resume()V @20: putfield
Reason:
Type 'bolts/Task$TaskCompletionSource' (current frame, stack[1]) is not assignable to 'bolts/TaskCompletionSource'
Current Frame:
bci: @20
flags: { }
locals: { 'com/parse/ParsePinningEventuallyQueue' }
stack: { 'com/parse/ParsePinningEventuallyQueue', 'bolts/Task$TaskCompletionSource' }
Bytecode:
0x0000000: 2ab6 0028 9900 1f2a b400 1a01 b600 2a57
0x0000010: 2ab8 002b b500 1a2a b400 1a01 b600 2a57
0x0000020: a700 0a2a b800 2bb5 001a 2ab7 000c 57b1
0x0000030:
Stackmap Table:
same_frame(@35)
same_frame(@42)
at com.parse.Parse.getEventuallyQueue(Parse.java:616)
at com.parse.Parse.access$800(Parse.java:42)
at com.parse.Parse$1.call(Parse.java:410)
at com.parse.Parse$1.call(Parse.java:407)
at bolts.Task$3.run(Task.java:249)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
java.lang.VerifyError: Bad type on operand stack
Exception Details:
Location:
com/parse/ParseQuery.checkIfRunning(Z)V @37: putfield
Reason:
Type 'bolts/Task$TaskCompletionSource' (current frame, stack[1]) is not assignable to 'bolts/TaskCompletionSource'
Current Frame:
bci: @37
flags: { }
locals: { 'com/parse/ParseQuery', integer, 'java/lang/Object' }
stack: { 'com/parse/ParseQuery', 'bolts/Task$TaskCompletionSource' }
Bytecode:
0x0000000: 2ab4 0005 594d c22a b400 0499 000d bb00
0x0000010: 2f59 1230 b700 31bf 1b99 000f 2a04 b500
0x0000020: 042a b800 32b5 0003 2cc3 a700 084e 2cc3
0x0000030: 2dbf b1
Exception Handler Table:
bci [7, 42] => handler: 45
bci [45, 48] => handler: 45
Stackmap Table:
append_frame(@24,Object[#266])
same_frame(@40)
same_locals_1_stack_item_frame(@45,Object[#267])
chop_frame(@50,1)
at com.parse.OfflineObjectStore.getAsync(OfflineObjectStore.java:73)
at com.parse.CachedCurrentUserController$5$1.then(CachedCurrentUserController.java:240)
at com.parse.CachedCurrentUserController$5$1.then(CachedCurrentUserController.java:219)
at bolts.Task$14.run(Task.java:796)
at bolts.BoltsExecutors$ImmediateExecutor.execute(BoltsExecutors.java:105)
at bolts.Task.completeAfterTask(Task.java:787)
at bolts.Task.continueWithTask(Task.java:599)
at bolts.Task.continueWithTask(Task.java:610)
at com.parse.CachedCurrentUserController$5.then(CachedCurrentUserController.java:219)
at com.parse.CachedCurrentUserController$5.then(CachedCurrentUserController.java:216)
at com.parse.TaskQueue.enqueue(TaskQueue.java:69)
at com.parse.CachedCurrentUserController.getAsync(CachedCurrentUserController.java:216)
at com.parse.CachedCurrentUserController.getAsync(CachedCurrentUserController.java:105)
at com.parse.ParseUser.getCurrentUserAsync(ParseUser.java:883)
at com.parse.Parse$3.then(Parse.java:430)
at com.parse.Parse$3.then(Parse.java:426)
at bolts.Task$14.run(Task.java:796)
at bolts.BoltsExecutors$ImmediateExecutor.execute(BoltsExecutors.java:105)
at bolts.Task.completeAfterTask(Task.java:787)
at bolts.Task.continueWithTask(Task.java:599)
at bolts.Task.continueWithTask(Task.java:610)
at com.parse.Parse.initialize(Parse.java:426)
at com.parse.Parse.initialize(Parse.java:364)
at com.appprova.core.app.AppProvaApplication.onCreate(AppProvaApplication.java:40)
at com.appprova.core.app.AppProvaApplication_.onCreate(AppProvaApplication_.java:38)
at org.robolectric.internal.ParallelUniverse.setUpApplicationState(ParallelUniverse.java:160)
at org.robolectric.RobolectricTestRunner.setUpApplicationState(RobolectricTestRunner.java:454)
at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:252)
at org.robolectric.RobolectricTestRunner.runChild(RobolectricTestRunner.java:193)
at org.robolectric.RobolectricTestRunner.runChild(RobolectricTestRunner.java:56)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:159)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Process finished with exit code 255
答案 0 :(得分:0)
据我所知,当您使用Robolectric的测试运行器运行测试时,它将实例化您的Application类并执行其onCreate()
方法。
现在,在那个方法中,你正在初始化Parse,但Parse SDK可能依赖于Android框架,但没有 - Robolectric用自己的实现替换部分Android类,并使其他人未实现。这可能是您观察到的异常的原因。
您可以尝试使用指定的here解决方法并提供"测试"您的Application子类的版本,它不初始化Parse SDK(可能,您应该在进行单元测试时模拟与此SDK的所有交互)。
以下问题编辑:
如果你看一下this question,你会发现这个异常可能会抛出,因为Parse SDK是针对某些类进行编译的,这些类是" mocked"通过Robolectric。换句话说,找到依赖类,但它们的字节码与预期的不同。
现在,您可以尝试找到解决此问题的方法(这根本不重要),但我没有看到任何理由这样做。如果我理解正确,你想要对你的应用程序与Parse的集成进行单元测试,这很好。但是,为了做到这一点,你真的不需要实际的Parse SDK - 你可以(和恕我直言)应该嘲笑它。否则,您的单元测试将取决于该SDK的功能,这通常是一个坏主意,并将导致" flaky"试验。如果你模拟这个SDK进行单元测试,那么你真的不需要在Application的子类中初始化它,我的初步建议仍然存在。
答案 1 :(得分:0)
Parse 使用的问题之一是您必须扩展ParseObject
。如何解决它有两种方法。
核心对象的接口
interface User{}
interface UserCreator {
@NonNull
User createUser();
}
在存储层中实现类
public class ParseUser extends ParseObject implements User {}
public class ParseUserCreator {}
我们在一个项目中采用了这种方法,而且我一直在填写它很复杂且不方便。毕竟,我发现了一篇证明我填充的文章。
“复制”核心对象 class User {}
并在存储层
class ParseUser {
public void fromUser(@NonNull final User user){}
@NonNull
public User toUser(){}
}
class Storage {
@NonNull
public User loadUser() {
ParseUser user = ...;
return
}
}
这种方法我更喜欢,但与此同时,我并不相信这是最好的方法。两种变体都完全隐藏了来自其他应用程序的 Parse ,这使得代码更清晰,如果您决定使用其他框架或库,则可以替换 Parse 。
快乐的编码!
答案 2 :(得分:0)
我这样更改运行配置: -VM选项:-noverify -代码覆盖率:选择JaCoCo的覆盖率赛跑者。
这些步骤可以解决问题。