android - How to call onStartCommand multiple times in a test? -
i have following design:
public class myservice extends service{ protected logger _log; int _counter; onstartcommand(...){ _log.print (++_counter); } } public class myservicetestwrapper extends myservice{ public void setlog(logger mocklogger){ _logger = mocklogger; } } public class myservicetest extends servicetestclass<myservicetestwrapper>{ public void test_mytest(){ logger fakelogger = mockito.mock(logger.class); // here im not sure how continue... //... //... mockito.verify(fakelogger.write(mockito.any(string.class))).times(3); } }
how service instance , make 3 calls onstartcommand?
thanks help
every time call startservice (even if running), onstartcommand
called.
so, call 3 times, can write:
intent serviceintent = new intent(mainactivity.this, myserivce.class); (int x = 0; x < 3; x++) { startservice(serviceintent); }
source: android docs (as shown below)
note multiple calls context.startservice() not nest (though result in multiple corresponding calls onstartcommand())
Comments
Post a Comment