我可以测试状态栏通知使用Android的测试框架? [英] Can I test status bar notifications using Android's testing framework?
本文介绍了我可以测试状态栏通知使用Android的测试框架?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有发在Android的状态栏通知的类。我无法找到一个方法来测试通知是否发送或没有,这使得它非常难写任何一种有用的单元测试。
I have a class that sends a status bar notification in Android. I can't find a way to test whether the notification was sent or not, which makes it very hard to write any kind of useful unit test.
有没有人有一个解决方案吗?
Does anyone have a solution for this?
推荐答案
也许不是你正在寻找的答案,但像往常一样,解决办法是:
Maybe not the answer you are looking for, but as usual the solution is to:
- 创建一个接口抽象的通知功能。
- 创建一个默认的实现委托给系统通知API。
- 在当前运行测试替代(或装饰)与支持测试模拟实现的默认实现。
这可以用下面的技术被简化:
This can be simplified with the following technology:
- 依赖注入框架(如RoboGuice),以简化实施的选择。
- 惩戒库(如EasyMock的)来自动生成模拟的实现。
这篇关于我可以测试状态栏通知使用Android的测试框架?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文