Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Service Testing

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

like image 312
alexkipar Avatar asked Oct 26 '22 05:10

alexkipar


1 Answers

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.

like image 186
Surya Wijaya Madjid Avatar answered Nov 11 '22 11:11

Surya Wijaya Madjid