mockitoandroid_解决android - Espresso + mockito - Mock activity launch

google官网上为开发者们介绍了Espresso测试框架,在之前的文章中已经讲到,该文章主要讲利用Espresso框架时如何获得测试代码覆盖率。 写了个例子在Github上: gi

I'm a beginner in android tests and what I would like to know is very simple. I have a button which launch an activity on click and instead of launching the real activity I would like to replace it by the launch of another one. How can I achieve that? I'm using Espresso and mockito 2.0+. Thank you.

android

mockito

android-testing

android-espresso

|

this question asked Apr 7 '15 at 10:49

E-Kami 802 2 12 30 1   This would require intrusive changes to your app -- i.e., adding a "test mode" flag and custom logic for starting a different activity in test mode. Can you explain the motivation for this? Maybe we can suggest alternatives. –

Daniel Lubarov Apr 13 '15 at 18:28

|

1 Answers

1

解决方法

I doubt that this question still need an answer but in cas, just know that Dependency Injection like dagger will do the job. Inject your real activity on your app and another activity in your test by loading a different module.

|

this answer answered Aug 31 '15 at 9:46

Nicolas Massart 170 1 13

|

1.intent 决定Activity所在的Task(Activity 堆栈) 对于"standard" 和 "singleTop" 模式, 是task在产生intent,除非intent里设置了FLAG_ACTIVITY_NEW_TASK 标

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值