android - 如何避免使用 mockito 的 onPause()?

标签 android unit-testing testing mockito

我有这个方法

@Override
protected void onPause() {
    unsuscribeFromMessageDispatcher(RaffleListActivity.this);
    Intent service = new Intent(this, AsyncIntentService.class);
    service.putExtra("TASK", TASKID_GET_RAFFLE_LIST);
    stopService(service);
    super.onPause();
}

当我进行测试时,如果在 super.onPause(); 中失败,我怎样才能避免使用 mockito 这一行?

最佳答案

据我所知,您无法使用 Mockito 执行此操作。但是你可以用 PowerMock :

@RunWith(PowerMockRunner.class)
@PrepareForTest(YourTestClass.class)
public class YourTest {

    @Test
    public void test() throws Exception {
        MemberModifier.suppress(MemberMatcher.method(YourParentClass.class, "onPause"));
        YourTestClass c = new YourTestClass();
          //super.onPause() will not be called here
        c.onPause();
    }

关于android - 如何避免使用 mockito 的 onPause()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33444063/

相关文章:

android - 跨多个 Activity/fragment 同步数据

java - 如何在我的代码中对 try catch block 进行 Junit 测试

swift - `swift test` 产生 "symbol(s) not found for architecture x86_64"链接器错误

java - Java7 nio2 有任何可用的内存文件系统实现吗?

android - .isDisplayed - Selenium + Appium

java - 为什么代码被调用2次? Java Android 线程处理程序

android - 无法将 firebase 添加到 android (flutter)

android - 如何制作启用单点登录的 facebook 应用程序?

unit-testing - 让 'go test -run <case>' 成功为 'go test' 的一般规则是什么?

java - Salesforce:调用方法并将联系人与 apex 测试方法的帐户相关联?