2

我正面临这个问题,基本上 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);
    }
}
4

1 回答 1

0

尝试这个:

    @Rule
public final ServiceTestRule mServiceRule = ServiceTestRule.withTimeout(60L, TimeUnit.SECONDS);
于 2017-01-31T12:42:47.477 回答