Android Service Testing

六眼飞鱼酱① 提交于 2020-01-01 10:29:08

问题


How to test my IBinder object that Service return on onBind ?


回答1:


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();

The ITestServiceCall is the interface that you define in an AIDL file (ITestServiceCall.aidl).

But before this can work you have to make sure your service returns the Stub of your interface correctly on onBind().

I hope this can help.



来源:https://stackoverflow.com/questions/793029/android-service-testing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!