Mockito和Powermock在android中测试

时间:2016-03-29 05:55:05

标签: android mockito powermock

如何使用协调器布局和上下文模拟静态构造函数作为参数。

public RequestHandler()
{         
    this.client = new AsyncHttpClient();
}
public static RequestHandler getInstance( CoordinatorLayout coordinatorLayout,Context context)
{
    if(instance == null){
        instance = new RequestHandler ();
    }
    instance.coordinatorLayout = coordinatorLayout;    
    instance.context=context;       
    notificationProvider = new NotificationProvider (coordinatorLayout);     
    instance.myUserSessionManager=new MyUserSessionManager (context);     
    return instance;
}

我得到了

  

无法模拟RequestHandler对象的构造   cz.msebera.android.httpclient.conn.ssl.SSLInitializationException

1 个答案:

答案 0 :(得分:0)

抱歉,您无法模拟静态方法。您只能模拟声明为非final的Java对象的实例方法。