ServiceTestCase< T> .getService?

我正在尝试在android上构建一个有效的junit测试套件。 由于我是Junit的新手,我无法弄清楚如何使用ServiceTestCase类。 我无法弄清楚如何使getService()方法工作。它永远让我无效。所以我决定通过startService启动它。这是行不通的。 请你帮助我好吗 ? 谢谢     
已邀请:
这是测试服务所需的
public class MyServiceTests extends ServiceTestCase<MyService> {

private static final String TAG = "MyServiceTests";

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

/**
 * Test basic startup/shutdown of Service
 */
@SmallTest
public void testStartable() {
    Intent startIntent = new Intent();
    startIntent.setClass(getContext(), MyService.class);
    startService(startIntent);
    assertNotNull(getService());
}

/**
 * Test binding to service
 */
@MediumTest
public void testBindable() {
    Intent startIntent = new Intent();
    startIntent.setClass(getContext(), MyService.class);
    IBinder service = bindService(startIntent);
    assertNotNull(service);
}
}
我写过一些关于Android测试和测试驱动开发的文章,你可能会发现它们很有用,请查看http://dtmilano.blogspot.com/search/label/test%20driven%20development。     
接受的答案不再适用。   像ActivityInstrumentationTestCase2或ServiceTestCase这样的TestCases是   不赞成使用ActivityTestRule或ServiceTestRule。 ATSL链接 他们似乎忘了更新实际文档。     

要回复问题请先登录注册