【问题标题】:How to suppress onSaveInstanceState using PowerMock如何使用 PowerMock 抑制 onSaveInstanceState
【发布时间】:2016-01-13 23:28:04
【问题描述】:

我试图从我的Activity 的父类中抑制onSaveInstanceState,但PowerMock 匹配FragmentActivity 类中具有相同签名的2 个方法,这似乎是不可能的。

我做错了什么?

这是我的设置

@Before
public void setup() {
    suppress(method(FragmentActivity.class, "onSaveInstanceState", Bundle.class));
}

这是我返回的异常

org.powermock.reflect.exceptions.TooManyMethodsFoundException: Several matching methods found, please specify the argument parameter types so that PowerMock can determine which method you're referring to.
Matching methods in class android.support.v4.app.FragmentActivity were:
void onSaveInstanceState( android.os.Bundle.class )
void onSaveInstanceState( android.os.Bundle.class )

【问题讨论】:

    标签: android unit-testing mockito powermock


    【解决方案1】:

    尝试methods 而不是method

    suppress(methods(FragmentActivity.class, "onSaveInstanceState"));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-12-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多