我是Android Studio的新手,我正在尝试测试GPS服务。我实际上使用了我在@dtmilano的另一个帖子中发现的一个示例,我没有收到任何错误,但测试失败。另一个帖子提到在测试中启动服务后添加thread.sleep(),但仍然失败。有人能告诉我我错过了什么吗?
这是我使用的例子:ServiceTestCase.getService?
import android.content.Intent;
import android.os.Handler;
import android.os.IBinder;
import android.test.MoreAsserts;
import android.test.ServiceTestCase;
public class GPSServiceTest extends ServiceTestCase<GPSService> {
public GPSServiceTest() {
super(GPSService.class);
}
@Override
protected void setUp() throws Exception {
super.setUp();
}
public void testOnStartCommand() throws Exception {
Intent startIntent = new Intent();
startIntent.setClass(getContext(), GPSService.class);
startService(startIntent);
Thread.sleep(10 * 1000);
assertNotNull(getService());
}
public void testBindable() {
Intent startIntent = new Intent();
startIntent.setClass(getContext(), GPSService.class);
IBinder service = bindService(startIntent);
assertNotNull(service);
}
}发布于 2016-06-04 06:13:09
像ActivityInstrumentationTestCase2或ServiceTestCase这样的
TestCases被弃用,取而代之的是ActivityTestRule或ServiceTestRule。
他们似乎忘记了更新实际的文档。
https://stackoverflow.com/questions/30420569
复制相似问题