Android的服务测试 [英] Android Service Testing
本文介绍了Android的服务测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何测试我的IBinder对象上onBind服务回报?
How to test my IBinder object that Service return on onBind ?
推荐答案
它是根据你的环境和服务(远程呼叫方案)之间使用远程接口。
例如,你可以这样做:
It's according to the remote interface that you use between your context and the service (in remote call scenario). For example you can do like this:
IBinder service = this.bindService(new Intent(TestService.class.getName()));
assertNotNull(service);
assertTrue(service instanceof ITestServiceCall); //see if the service returns the correct interface
ITestServiceCall iTestServiceCall = ITestServiceCall.Stub.asInterface(service);
assertNotNull(iTestServiceCall);
iTestServiceCall.doSomething();
该ITestServiceCall是您在AIDL文件定义接口( ITestServiceCall.aidl )。
不过,在此之前可以工作,你必须确保你的服务正确返回你的接口的存根上的 onBind()
But before this can work you have to make sure your service returns the Stub of your interface correctly on onBind().
我希望这能有所帮助。
这篇关于Android的服务测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文