我有这个方法
@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/