久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

嘗試模擬任何類都會生成 ExceptionInInitializerError

Attempt to mockito mock any class generates ExceptionInInitializerError(嘗試模擬任何類都會生成 ExceptionInInitializerError)
本文介紹了嘗試模擬任何類都會生成 ExceptionInInitializerError的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

當我運行以下代碼時:

public class ActivityTest extends ActivityInstrumentationTestCase2<MainActivity> {
    ....
    public void testCanCreateMockito() {
        List mockedList = Mockito.mock(List.class);
    }
}

我得到以下異常:

java.lang.ExceptionInInitializerError
at org.mockito.internal.creation.cglib.ClassImposterizer.createProxyClass(ClassImposterizer.java:95)
at org.mockito.internal.creation.cglib.ClassImposterizer.imposterise(ClassImposterizer.java:57)
at org.mockito.internal.creation.cglib.ClassImposterizer.imposterise(ClassImposterizer.java:49)
at org.mockito.internal.creation.cglib.CglibMockMaker.createMock(CglibMockMaker.java:24)
at org.mockito.internal.util.MockUtil.createMock(MockUtil.java:33)
at org.mockito.internal.MockitoCore.mock(MockitoCore.java:59)
at org.mockito.Mockito.mock(Mockito.java:1285)
at org.mockito.Mockito.mock(Mockito.java:1163)
at com.acesounderglass.hungertracker.ActivityTest.testCanCreateMockito(ActivityTest.java:60)
at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:214)
at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:199)
at android.test.ActivityInstrumentationTestCase2.runTest(ActivityInstrumentationTestCase2.java:192)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:191)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:176)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:555)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1837)
Caused by: org.mockito.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null
at org.mockito.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:238)
at org.mockito.cglib.core.KeyFactory$Generator.create(KeyFactory.java:145)
at org.mockito.cglib.core.KeyFactory.create(KeyFactory.java:117)
at org.mockito.cglib.core.KeyFactory.create(KeyFactory.java:109)
at org.mockito.cglib.core.KeyFactory.create(KeyFactory.java:105)
at org.mockito.cglib.proxy.Enhancer.<clinit>(Enhancer.java:70)
... 23 more
Caused by: java.lang.reflect.InvocationTargetException
at org.mockito.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:385)
at org.mockito.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:220)
... 28 more
Caused by: java.lang.UnsupportedOperationException: can't load this type of class file
at java.lang.ClassLoader.defineClass(ClassLoader.java:300)
... 32 more

這發生在任何類中,List 只是一個簡單的例子.我的 gradle 依賴項是:

This occurs with any class, List was just an easy example. My gradle dependencies are:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.0'
    androidTestCompile "org.mockito:mockito-core:1.+"
    androidTestCompile files('libs/dexmaker-mockito-1.0.jar')
    androidTestCompile files('libs/dexmaker-1.0.jar')
}

我已將 gradle 升級到 1.1,嘗試使用實驗性單元測試功能,但沒有,似乎沒有任何區別.怎么回事?

I've upgraded gradle to 1.1, tried using the experimental unit test feature and not, nothing seems to make a difference. What's going on?

推薦答案

我在缺少兩個 dexmaker 依賴項時收到此錯誤.

I received this error when I was missing the two dexmaker dependencies.

將這些行添加到 app/gradle.build 文件對我有用.

Adding these lines to the app/gradle.build file is working for me.

androidTestCompile 'org.mockito:mockito-core:1.10.19'
androidTestCompile 'com.google.dexmaker:dexmaker:1.2'
androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.2'

我也在使用 Android Studio,發現更改依賴項后重啟 AS 是個好主意.

I am also using Android Studio and have found it to be a good idea to restart AS after altering the dependencies.

這篇關于嘗試模擬任何類都會生成 ExceptionInInitializerError的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

EditText: Disable Paste/Replace menu pop-up on Text Selection Handler click event(EditText:禁用文本選擇處理程序單擊事件上的粘貼/替換菜單彈出)
Multiline EditText with Done SoftInput Action Label on 2.3(2.3 上帶有完成 SoftInput 操作標簽的多行 EditText)
How to detect the swipe left or Right in Android?(如何在 Android 中檢測向左或向右滑動?)
Prevent dialog dismissal on screen rotation in Android(防止在Android中的屏幕旋轉對話框解除)
How do I handle ImeOptions#39; done button click?(如何處理 ImeOptions 的完成按鈕點擊?)
How do you set EditText to only accept numeric values in Android?(您如何將 EditText 設置為僅接受 Android 中的數值?)
主站蜘蛛池模板: 天天干天天爱天天操 | 欧美日韩视频一区二区 | h片在线看 | 综合色久 | 欧美视频免费在线 | 一区二区精品 | 欧美成人精品激情在线观看 | 成人在线视频一区 | 精品国产一区二区三区性色av | 人妖一区 | 中文字幕第十五页 | 成人在线精品 | 亚洲精品日韩一区二区电影 | 亚洲一区久久 | 天天宗合网 | 岛国av一区二区三区 | 欧美偷偷操 | 337p日本欧洲亚洲大胆精蜜臀 | 日韩成人精品 | 国产草草视频 | 婷婷久久精品一区二区 | 亚洲一区三区在线观看 | 成人久草 | 中文字幕日韩一区 | 亚洲精品黄 | 欧美日本在线 | av第一页 | 欧美成人免费在线视频 | 亚洲精品中文字幕在线 | 国产在线一区二区三区 | 人人干人人草 | 国产丝袜一区二区三区免费视频 | 精品久久久久久久人人人人传媒 | 欧美激情va永久在线播放 | 99久久久久 | 爱草在线 | a级在线免费观看 | 99热都是精品 | 古装三级在线播放 | 亚洲综合视频 | 精品国产免费一区二区三区演员表 |