I'm trying to test an external binding to a Service I've defined. Following the class I'm using for instrumented test:
@Rule
public final ServiceTestRule serviceRule = new ServiceTestRule();
@Test
public void testWithBoundService() throws TimeoutException, RemoteException {
IMyInterface iMyInterface;
Intent serviceIntent =
new Intent(ApplicationProvider.getApplicationContext(),
MyService.class);
IBinder binder = serviceRule.bindService(serviceIntent);
assertNotNull(binder);
iMyInterface = IMyInterface.Stub.asInterface(binder);
assertTrue(iMyInterface.retrieveValue(new Attribute()).getValues().get(0).equals("home"));
}
@Test
public void testWithBoundServiceExternal() throws TimeoutException, RemoteException {
IMyInterface iMyInterface;
Intent serviceIntent = new Intent();
serviceIntent.setClassName("a.b.c.d", "a.b.c.d.MyService");
IBinder binder = serviceRule.bindService(serviceIntent);
assertNotNull(binder);
iMyInterface = IMyInterface.Stub.asInterface(binder);
boolean reachedHere = false;
assertTrue(iMyInterface.retrieveValue(new Attribute()).getValues().get(0).equals("home"));
}
First Test function runs without any errors, the second fails with the following message:
Failed to bind to service! Is your service declared in the manifest?
The Service is defined in the package a.b.c.d, the same of the Aidl interface, while the instrumentedTest is running in the a.b.c.e package