Can not get Android ServiceTestCase to run

别说谁变了你拦得住时间么 提交于 2019-12-05 10:41:18

Make sure that you provide a default constructor for the ServiceTestCase. The one Eclipse generates for you may not be appropriate. For example, in my case Eclipse generated for me:

public class MyServiceTestCase extends ServiceTestCase<MyService> {

  public MyServiceTestCase(Class<MyService> serviceClass) {
    super(serviceClass);
  }
  ...
}

Android JUnit was not able to instantiate MyServiceTestCase, but it did not complain, and I only could see that no test cases where run.

Thefore I replaced the constructor with the following, and it worked nicely:

public class MyServiceTestCase extends ServiceTestCase<MyService> {

  public MyServiceTestCase() {
    super(MyService.class);
  }
  ...
}

Hope it works for you.

The accepted answer doesn't work for me any more.

TestCases like ActivityInstrumentationTestCase2 or ServiceTestCase are deprecated in favor of ActivityTestRule or ServiceTestRule.

ATSL link

It seems they forgot to update the actual documentation.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!