首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android ServiceTestCase总是失败?

Android ServiceTestCase总是失败?
EN

Stack Overflow用户
提问于 2015-05-24 13:59:44
回答 1查看 319关注 0票数 1

我是Android Studio的新手,我正在尝试测试GPS服务。我实际上使用了我在@dtmilano的另一个帖子中发现的一个示例,我没有收到任何错误,但测试失败。另一个帖子提到在测试中启动服务后添加thread.sleep(),但仍然失败。有人能告诉我我错过了什么吗?

这是我使用的例子:ServiceTestCase.getService?

代码语言:javascript
复制
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);
    }

}
EN

回答 1

Stack Overflow用户

发布于 2016-06-04 06:13:09

像ActivityInstrumentationTestCase2或ServiceTestCase这样的

TestCases被弃用,取而代之的是ActivityTestRule或ServiceTestRule。

ATSL link

他们似乎忘记了更新实际的文档。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30420569

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档