I have a service (lets call it A) and it relies on services B and C.
I want to unit test A, so I would ideally like to capture any intents emitted from the service that would start B or C and replace the results with a mock instance of the services. However, Android's test setup doesn't seem to have an obvious way of implementing this.
Espresso intents seems to be the nearest to this but it doesn't seem to cover binding to a service. Does anyone know how to do this?
A is getting a binder to B and C via code like...
Intent intent = new Intent(context, B.class);
context.bindService(intent, mServiceConnection, Context.BIND_AUTO_CREATE);
...
private final ServiceConnection mServiceConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
B.BinderStub bInstance = (B.BinderStub) service;
}
...
from How do I create a mock service in an Android test?
No comments:
Post a Comment