Issue
I want to write a unit test that starts the test when a message is received at my GcmListenerService,I tried to bind to the the GcmListenerService but it is not possible because GcmListenerService overrides onBind with such that the method can't be overridden.
starting the service from my test doesn't make sense because I want it bo be invoked when a message is received from the server.
any ideas ?
Solution
I have found a solution by creating a GCMListenerService object,I hope this is the right way.
public class mytest{
private GCMListenerService mReceiver;
private Context context;
@Before
public void init() {
context = InstrumentationRegistry.getTargetContext();
mReceiver=new GCMListenerService(context);
}
@Test
public void testGPS() {
Bundle bundle = new Bundle();
bundle.putString("message", Constants.GET_LOCATION);
mReceiver.onMessageReceived("maxim",bundle);
}
}
Answered By - Maxim Toyberman
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.