ServiceTestCase< T> .getService? [英] ServiceTestCase<T>.getService?

查看:156
本文介绍了ServiceTestCase< T> .getService?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图建立一个有效的JUnit测试套件的机器人。

I'm trying to build a valid junit testing suite on android.

由于我是新来的Junit我无法弄清楚如何使用ServiceTestCase类。

Since i'm new to Junit i can't figure out how to use the ServiceTestCase class.

我无法弄清楚如何获得的getService()方法的工作。它曾经返回我空。所以我决定通过startService启动它。这不可行。

I can't figure it out how to get the getService() method working. it ever returns me null . So i decided to start it via startService. It does not work.

你能帮帮我吗?

感谢

推荐答案

这就是你需要测试你的服务

This is what you need to test your service

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的测试和测试驱动开发,你会发现有用的,检查<一href="http://dtmilano.blogspot.com/search/label/test%20driven%20development">http://dtmilano.blogspot.com/search/label/test%20driven%20development.

这篇关于ServiceTestCase&LT; T&GT; .getService?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆