Attempt to mockito mock any class generates ExceptionInInitializerError

前端 未结 7 1505
無奈伤痛
無奈伤痛 2020-12-16 09:26

When I run the following code:

public class ActivityTest extends ActivityInstrumentationTestCase2 {
    ....
    public void testCanCreat         


        
7条回答
  •  不思量自难忘°
    2020-12-16 10:08

    I was getting this because I was using proguard for my debug builds because of the 65K method limit (Yes, I need to cut down on the number of dependencies), and that was causing this error for me.

    I added this in my (debug) proguard config to solve it:

    ### Keep Mockito
    -keep class org.mockito.** { *; }
    -keep interface org.mockito.** { *; }
    -keep class com.google.dexmaker.** { *; }
    -keep interface com.google.dexmaker.** { *; }
    

    Not sure If I really need all four of those lines, but this did the trick.

提交回复
热议问题