Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/190.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android PowerMock+;莫基托+;JUnit:ExceptionInInitializeError调用PowerMockito.spy()时_Android_Eclipse_Junit_Mockito_Powermock - Fatal编程技术网

Android PowerMock+;莫基托+;JUnit:ExceptionInInitializeError调用PowerMockito.spy()时

Android PowerMock+;莫基托+;JUnit:ExceptionInInitializeError调用PowerMockito.spy()时,android,eclipse,junit,mockito,powermock,Android,Eclipse,Junit,Mockito,Powermock,我在Eclipse(Neon)中创建的Android测试项目中使用PowerMock。当我运行一个基本测试用例时,调用PowerMockito.spy()时,我收到一个ExceptionInInitializationError 以下是报告的stacktrace: I/TestRunner(30132): started: testAndroidTestCaseSetupProperly(com.fuelpowered.lib.propeller.test.JPTestCase) I/TestR

我在Eclipse(Neon)中创建的Android测试项目中使用PowerMock。当我运行一个基本测试用例时,调用
PowerMockito.spy()
时,我收到一个ExceptionInInitializationError

以下是报告的stacktrace:

I/TestRunner(30132): started: testAndroidTestCaseSetupProperly(com.fuelpowered.lib.propeller.test.JPTestCase)
I/TestRunner(30132): finished: testAndroidTestCaseSetupProperly(com.fuelpowered.lib.propeller.test.JPTestCase)
I/TestRunner(30132): passed: testAndroidTestCaseSetupProperly(com.fuelpowered.lib.propeller.test.JPTestCase)
I/TestRunner(30132): started: testJP(com.fuelpowered.lib.propeller.test.JPTestCase)
I/ActivityManager(  757): Start proc 30167:com.spryfox.tripletown/u0a199 for broadcast com.spryfox.tripletown/com.heyzap.sdk.ads.PackageAddedReceiver
I/TestRunner(30132): failed: testJP(com.fuelpowered.lib.propeller.test.JPTestCase)
I/TestRunner(30132): ----- begin exception -----
I/TestRunner(30132): 
I/TestRunner(30132): java.lang.ExceptionInInitializerError
I/TestRunner(30132):    at org.powermock.api.mockito.repackaged.ClassImposterizer.createProxyClass(ClassImposterizer.java:95)
I/TestRunner(30132):    at org.powermock.api.mockito.repackaged.ClassImposterizer.imposterise(ClassImposterizer.java:57)
I/TestRunner(30132):    at org.powermock.api.mockito.internal.mockcreation.MockCreator.createMethodInvocationControl(MockCreator.java:110)
I/TestRunner(30132):    at org.powermock.api.mockito.internal.mockcreation.MockCreator.mock(MockCreator.java:58)
I/TestRunner(30132):    at org.powermock.api.mockito.PowerMockito.spy(PowerMockito.java:234)
I/TestRunner(30132):    at com.fuelpowered.lib.propeller.test.JPTestCase.testJP(JPTestCase.java:18)
I/TestRunner(30132):    at java.lang.reflect.Method.invoke(Native Method)
I/TestRunner(30132):    at java.lang.reflect.Method.invoke(Method.java:372)
I/TestRunner(30132):    at junit.framework.TestCase.runTest(TestCase.java:168)
I/TestRunner(30132):    at junit.framework.TestCase.runBare(TestCase.java:134)
I/TestRunner(30132):    at junit.framework.TestResult$1.protect(TestResult.java:115)
I/TestRunner(30132):    at junit.framework.TestResult.runProtected(TestResult.java:133)
I/TestRunner(30132):    at junit.framework.TestResult.run(TestResult.java:118)
I/TestRunner(30132):    at junit.framework.TestCase.run(TestCase.java:124)
I/TestRunner(30132):    at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:191)
I/TestRunner(30132):    at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:176)
I/TestRunner(30132):    at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:555)
I/TestRunner(30132):    at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1853)
I/TestRunner(30132): Caused by: org.mockito.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null
I/TestRunner(30132):    at org.mockito.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:238)
I/TestRunner(30132):    at org.mockito.cglib.core.KeyFactory$Generator.create(KeyFactory.java:145)
I/TestRunner(30132):    at org.mockito.cglib.core.KeyFactory.create(KeyFactory.java:117)
I/TestRunner(30132):    at org.mockito.cglib.core.KeyFactory.create(KeyFactory.java:109)
I/TestRunner(30132):    at org.mockito.cglib.core.KeyFactory.create(KeyFactory.java:105)
I/TestRunner(30132):    at org.mockito.cglib.proxy.Enhancer.<clinit>(Enhancer.java:70)
I/TestRunner(30132):    ... 18 more
I/TestRunner(30132): Caused by: java.lang.reflect.InvocationTargetException
I/TestRunner(30132):    at java.lang.reflect.Method.invoke(Native Method)
I/TestRunner(30132):    at java.lang.reflect.Method.invoke(Method.java:372)
I/TestRunner(30132):    at org.mockito.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:385)
I/TestRunner(30132):    at org.mockito.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:220)
I/TestRunner(30132):    ... 23 more
I/TestRunner(30132): Caused by: java.lang.UnsupportedOperationException: can't load this type of class file
I/TestRunner(30132):    at java.lang.ClassLoader.defineClass(ClassLoader.java:300)
I/TestRunner(30132):    ... 27 more
I/TestRunner(30132): ----- end exception -----
I/TestRunner(30132): finished: testJP(com.fuelpowered.lib.propeller.test.JPTestCase)
D/AndroidRuntime(30094): Shutting down VM
I/ActivityManager(  757): Force stopping com.fuelpowered.lib.propeller.test appid=10324 user=0: finished inst
I/ActivityManager(  757): Killing 30132:com.fuelpowered.lib.propeller.test/u0a324 (adj 0): stop com.fuelpowered.lib.propeller.test 
正在监视的MyStaticClass.java类:

package com.fuelpowered.lib.propeller.test;

public class MyStaticClass {

    public static String foo() {
        return bar();
    }

    public static String bar() {
        return "bar";
    }

}
AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.fuelpowered.lib.propeller.test"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="10"
        android:targetSdkVersion="23" />

    <instrumentation
        android:name="android.test.InstrumentationTestRunner"
        android:targetPackage="com.fuelpowered.lib.propeller.test" />

    <application
        android:allowBackup="false"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <uses-library android:name="android.test.runner" />
    </application>

</manifest>

.  jar库是从数据库中获取的

为了使这些库能够很好地相互编译,我必须修改并重新打包mockito-all-1.10.19.jar和powermock-mockito-1.6.2-full.jar库,因为它们与其他.jar库存在以下冲突:

  • mockito-all-1.10.19.jar中的/LICENSE、/NOTICE和/asm-LICENSE.txt文件与cglib-nodep-2.2.2.jar中存在同名文件冲突,因此它们被重命名
  • ./mockito extensions/org.mockito.plugins.MockMaker文件powermock-mockito-1.6.1-full.jar与dexmaker-mockito-1.4.jar中存在同名文件冲突,因此该文件已从powermock.jar库中删除
此外,powermock-mockito-junit-1.6.2.zip存档中包含的整个objenesis-2.1.jar库存在冲突,因为它的内容已经包含在mockito-all-1.10.19.jar库中,所以我没有将该库包含在测试项目中

该测试用例在模拟器(Nexus 5、Google API、API 21)和设备(Nexus 5、Android 5.1.1)上都进行了尝试


这几乎描述了所有的项目设置和源。我已经试着在互联网上搜索了一段时间,但我仍然不知道我的设置中有什么错误或遗漏,所以如果有任何帮助,我将不胜感激。提前谢谢

出现此错误是因为必须将实例传递给PowerMockito.spy方法。应该是这样的:

PowerMockito.spy(new MyStaticClass());

出现此错误是因为必须将实例传递给PowerMockito.spy方法。应该是这样的:

PowerMockito.spy(new MyStaticClass());

您使用的是maven、gradle、ivy或类似软件吗?没有,我一直在手动管理依赖项和构建路径我怀疑您是否开始使用能够解决此问题的软件。您使用的是maven、gradle、ivy或类似软件吗?没有,我一直在手动管理依赖项和构建路径,如果您开始使用能够解决此问题的依赖项和构建路径,我会怀疑。