我正面临这个问题,基本上 ServiceTestRule 在未绑定服务中调用 startService 时会引发 TimeoutException,并且想知道在发布修复程序之前是否有人知道可能的解决方法?
未绑定的服务类:
public class UnboundService extends Service {
@Override
public IBinder onBind(Intent intent) {
return null;
}
}
测试类:
@RunWith(AndroidJUnit4.class)
@MediumTest
public class UnboundServiceTest {
@Rule
public final ServiceTestRule serviceRule = new ServiceTestRule();
@Test
public void worksAsStartedService() throws TimeoutException {
Intent intent = new Intent(InstrumentationRegistry.getTargetContext(), UnboundService.class);
serviceRule.startService(intent);
}
}